﻿
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>ES5规范 · Sqlrule</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Sqlrule">
        
        
    
    <link rel="stylesheet" href="css/style.css">

    
            
                
                <link rel="stylesheet" href="css/search.css">
                
            
                
                <link rel="stylesheet" href="css/plugin.css">
                
            
                
                <link rel="stylesheet" href="css/splitter.css">
                
            
                
                <link rel="stylesheet" href="css/plugin_1.css">
                
            
                
                <link rel="stylesheet" href="css/website.css">
                
            
                
                <link rel="stylesheet" href="css/website_1.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="JavaScript_ES6_ReleasedVersion.html" />
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    认证体系概览
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" >
            
                <span>
            
                    
                    Oracle规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1.1" data-path="../../Database/design_Oracle/design_Oracle_ReleasedVersion.html">
            
                <a href="../../Database/design_Oracle/design_Oracle_ReleasedVersion.html">
            
                    
                    设计规范 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.1.2" data-path="../../Database/dev_Oracle/dev_Oracle_ReleasedVersion.html">
            
                <a href="../../Database/dev_Oracle/dev_Oracle_ReleasedVersion.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.1.3" data-path="../../Database/operation_Oracle/operation_Oracle_ReleasedVersion.html">
            
                <a href="../../Database/operation_Oracle/operation_Oracle_ReleasedVersion.html">
            
                    
                    运维规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.2" >
            
                <span>
            
                    
                    MySQL规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.2.1" data-path="../../Database/design_MySQL/design_MySQL_ReleasedVersion.html">
            
                <a href="../../Database/design_MySQL/design_MySQL_ReleasedVersion.html">
            
                    
                    设计规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2.2" data-path="../../Database/dev_MySQL/dev_MySQL_ReleasedVersion.html">
            
                <a href="../../Database/dev_MySQL/dev_MySQL_ReleasedVersion.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2.3" data-path="../../Database/operation_MySQL/operation_MySQL_ReleasedVersion.html">
            
                <a href="../../Database/operation_MySQL/operation_MySQL_ReleasedVersion.html">
            
                    
                    运维规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.3" >
            
                <span>
            
                    
                    TimesTen规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.3.1" data-path="../../Database/design_TimesTen/design_TimesTen_ReleasedVersion.md">
            
                <span>
            
                    
                    设计规范（暂缺）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.2" data-path="../../Database/dev_TimesTen/dev_TimesTen_ReleasedVersion.html">
            
                <a href="../../Database/dev_TimesTen/dev_TimesTen_ReleasedVersion.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.3" data-path="../../Database/operation_TimesTen/operation_TimesTen_ReleasedVersion.html">
            
                <a href="../../Database/operation_TimesTen/operation_TimesTen_ReleasedVersion.html">
            
                    
                    运维规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.4" >
            
                <span>
            
                    
                    QMDB规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.4.1" data-path="../../Database/design_QMDB/design_QMDB_ReleasedVersion.md">
            
                <span>
            
                    
                    设计规范（暂缺）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.4.2" data-path="../../Database/dev_QMDB/dev_QMDB_ReleasedVersion.html">
            
                <a href="../../Database/dev_QMDB/dev_QMDB_ReleasedVersion.html">
            
                    
                    开发规范(建设中)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.4.3" data-path="../../Database/operation_QMDB/operation_QMDB_ReleasedVersion.html">
            
                <a href="../../Database/operation_QMDB/operation_QMDB_ReleasedVersion.html">
            
                    
                    运维规范(建设中)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.5" >
            
                <span>
            
                    
                    HBase规范(建设中)
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.5.1" data-path="../../Database/design_HBase/design_HBase_ReleasedVersion.md">
            
                <span>
            
                    
                    设计规范（暂缺）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.5.2" data-path="../../Database/dev_HBase/dev_HBase_ReleasedVersion.html">
            
                <a href="../../Database/dev_HBase/dev_HBase_ReleasedVersion.html">
            
                    
                    开发规范（建设中）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.5.3" data-path="../../Database/operation_HBase/operation_HBase_ReleasedVersion.md">
            
                <span>
            
                    
                    运维规范（暂缺）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.6" >
            
                <span>
            
                    
                    Redis规范(建设中)
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.6.1" data-path="../../Database/design_Redis/design_Redis_ReleasedVersion.md">
            
                <span>
            
                    
                    设计规范（暂缺）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.6.2" data-path="../../Database/dev_Redis/dev_Redis_ReleasedVersion.md">
            
                <span>
            
                    
                    开发规范（暂缺）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.6.3" data-path="../../Database/operation_Redis/operation_Redis_ReleasedVersion.html">
            
                <a href="../../Database/operation_Redis/operation_Redis_ReleasedVersion.html">
            
                    
                    运维规范（建设中）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.7" >
            
                <span>
            
                    
                    Java开发规范(建设中)
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.7.1" data-path="../Java/Java_ReleasedVersion.html">
            
                <a href="../Java/Java_ReleasedVersion.html">
            
                    
                    编码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.7.2" >
            
                <a target="_blank" href="http://gitlab.iwhalecloud.com/CoP/Java-Coding-Specification/-/blob/master/jcs-Alibaba/%E3%80%8AJava%E5%BC%80%E5%8F%91%E6%89%8B%E5%86%8C%E3%80%8Bv1.5.0%20%E5%8D%8E%E5%B1%B1%E7%89%88.pdf">
            
                    
                    《Java开发手册》v1.5.0 华山版（在线版建设中）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.7.3" data-path="../Java/operation_JVM_ReleasedVersion.html">
            
                <a href="../Java/operation_JVM_ReleasedVersion.html">
            
                    
                    虚拟机运维规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.7.4" >
            
                <a target="_blank" href="http://gitlab.iwhalecloud.com/CoP/Java-Coding-Specification/-/blob/master/CERT-Standard/QIWC_33.001.1_2019%E6%B5%A9%E9%B2%B8%E7%A7%91%E6%8A%80Web%E5%BA%94%E7%94%A8%E5%AE%89%E5%85%A8%E5%BC%80%E5%8F%91%E8%A7%84%E8%8C%83.pdf">
            
                    
                    WEB应用安全开发规范（在线版建设中）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.7.5" >
            
                <a target="_blank" href="http://gitlab.iwhalecloud.com/CoP/Java-Coding-Specification/-/blob/master/CERT-Standard/QIWC_33.002.1_2019%E6%B5%A9%E9%B2%B8%E7%A7%91%E6%8A%80Java%E7%BC%96%E7%A0%81%E8%A7%84%E8%8C%83-%E5%AE%89%E5%85%A8%E7%AF%87.pdf">
            
                    
                    安全编码规范（在线版建设中）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.8" >
            
                <span>
            
                    
                    C++开发规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.8.1" data-path="../CPP/Cpp_ReleasedVersion.html">
            
                <a href="../CPP/Cpp_ReleasedVersion.html">
            
                    
                    编码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.8.2" data-path="../CPP/Cpp_CERT_ReleasedVersion.html">
            
                <a href="../CPP/Cpp_CERT_ReleasedVersion.html">
            
                    
                    安全编码规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.9" >
            
                <span>
            
                    
                    JavaScript开发规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.1.9.1" data-path="JavaScript_ES5_ReleasedVersion.html">
            
                <a href="JavaScript_ES5_ReleasedVersion.html">
            
                    
                    ES5规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.9.2" data-path="JavaScript_ES6_ReleasedVersion.html">
            
                <a href="JavaScript_ES6_ReleasedVersion.html">
            
                    
                    ES6规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.10" >
            
                <span>
            
                    
                    安全规范及规定
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.10.1" data-path="../../security/Security_Redline/Security_Redline_ReleasedVersion.html">
            
                <a href="../../security/Security_Redline/Security_Redline_ReleasedVersion.html">
            
                    
                    产品安全红线管理规定
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.10.2" data-path="../../security/Security_Design/Security_Design_ReleasedVersion.html">
            
                <a href="../../security/Security_Design/Security_Design_ReleasedVersion.html">
            
                    
                    产品设计安全规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.10.3" data-path="../../security/R&D_Security/R&D_Security_ReleasedVersion.html">
            
                <a href="../../security/R&D_Security/R&D_Security_ReleasedVersion.html">
            
                    
                    产品研发安全规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.10.4" data-path="../../security/O&M_Security/O&M_Security_ReleasedVersion.html">
            
                <a href="../../security/O&M_Security/O&M_Security_ReleasedVersion.html">
            
                    
                    交付运维安全规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.10.5" data-path="../../security/OSS_Management/PG_OSS_Management_ReleasedVersion.html">
            
                <a href="../../security/OSS_Management/PG_OSS_Management_ReleasedVersion.html">
            
                    
                    开源软件管理规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >ES5规范</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x547D;&#x540D;&#x89C4;&#x5219;"><b>1. </b>&#x547D;&#x540D;&#x89C4;&#x5219;</a></li><li><span class="title-icon "></span><a href="#&#x7A7A;&#x767D;"><b>2. </b>&#x7A7A;&#x767D;</a></li><li><span class="title-icon "></span><a href="#&#x9017;&#x53F7;"><b>3. </b>&#x9017;&#x53F7;</a></li><li><span class="title-icon "></span><a href="#&#x5206;&#x53F7;"><b>4. </b>&#x5206;&#x53F7;</a></li><li><span class="title-icon "></span><a href="#&#x53D8;&#x91CF;"><b>5. </b>&#x53D8;&#x91CF;</a></li><li><span class="title-icon "></span><a href="#&#x5BF9;&#x8C61;"><b>6. </b>&#x5BF9;&#x8C61;</a></li><li><span class="title-icon "></span><a href="#&#x6570;&#x7EC4;"><b>7. </b>&#x6570;&#x7EC4;</a></li><li><span class="title-icon "></span><a href="#&#x5B57;&#x7B26;&#x4E32;"><b>8. </b>&#x5B57;&#x7B26;&#x4E32;</a></li><li><span class="title-icon "></span><a href="#&#x51FD;&#x6570;"><b>9. </b>&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#&#x5C5E;&#x6027;"><b>10. </b>&#x5C5E;&#x6027;</a></li><li><span class="title-icon "></span><a href="#&#x8FD0;&#x7B97;&#x7B26;--&#x7B49;&#x53F7;"><b>11. </b>&#x8FD0;&#x7B97;&#x7B26; &amp; &#x7B49;&#x53F7;</a></li><li><span class="title-icon "></span><a href="#&#x5757;"><b>12. </b>&#x5757;</a></li><li><span class="title-icon "></span><a href="#&#x6CE8;&#x91CA;"><b>13. </b>&#x6CE8;&#x91CA;</a></li><li><span class="title-icon "></span><a href="#&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><b>14. </b>&#x7C7B;&#x578B;&#x8F6C;&#x6362;</a></li><li><span class="title-icon "></span><a href="#&#x6784;&#x9020;&#x51FD;&#x6570;"><b>15. </b>&#x6784;&#x9020;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#&#x4E8B;&#x4EF6;"><b>16. </b>&#x4E8B;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;"><b>17. </b>&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#ide&#x5DE5;&#x5177;&#x914D;&#x7F6E;"><b>18. </b>IDE&#x5DE5;&#x5177;&#x914D;&#x7F6E;</a></li><ul><li><span class="title-icon "></span><a href="#vscode-eslint&#x914D;&#x7F6E;"><b>18.1. </b>VSCODE ESLINT&#x914D;&#x7F6E;</a></li><li><span class="title-icon "></span><a href="#idea-eslint-&#x914D;&#x7F6E;"><b>18.2. </b>IDEA ESLINT &#x914D;&#x7F6E;</a></li></ul><li><span class="title-icon "></span><a href="#&#x672C;&#x6587;&#x4EF6;&#x8BC4;&#x5BA1;&#x3001;&#x4FEE;&#x6B63;&#x8BB0;&#x5F55;"><b>19. </b>&#x672C;&#x6587;&#x4EF6;&#x8BC4;&#x5BA1;&#x3001;&#x4FEE;&#x6B63;&#x8BB0;&#x5F55;</a></li></ul></div><a href="#&#x547D;&#x540D;&#x89C4;&#x5219;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><p><img src="picture/pg_es5.png" alt="&#x5C01;&#x9762;"></p>
<h1 id="&#x547D;&#x540D;&#x89C4;&#x5219;"><a name="&#x547D;&#x540D;&#x89C4;&#x5219;" class="anchor-navigation-ex-anchor" href="#&#x547D;&#x540D;&#x89C4;&#x5219;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x547D;&#x540D;&#x89C4;&#x5219;</h1>
<ul>
<li><p>&#x907F;&#x514D;&#x5355;&#x5B57;&#x6BCD;&#x547D;&#x540D;&#x3002;&#x547D;&#x540D;&#x5E94;&#x5177;&#x5907;&#x63CF;&#x8FF0;&#x6027;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">q</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// ...stuff...</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">query</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// ..stuff..</span>
}
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;&#x9A7C;&#x5CF0;&#x5F0F;&#x547D;&#x540D;&#x5BF9;&#x8C61;&#x3001;&#x51FD;&#x6570;&#x548C;&#x5B9E;&#x4F8B;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L19" target="_blank"><code>camelcase</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> this_is_my_object = {};
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">this_is_my_function</span>(<span class="hljs-params"></span>) </span>{}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> thisIsMyObject = {};
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">thisIsMyFunction</span>(<span class="hljs-params"></span>) </span>{}
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;&#x5E15;&#x65AF;&#x5361;&#x5F0F;&#x547D;&#x540D;&#x6784;&#x9020;&#x51FD;&#x6570;&#x6216;&#x7C7B;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L215" target="_blank"><code>new-cap</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> bad = {};
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">user</span>(<span class="hljs-params">options</span>) </span>{
    <span class="hljs-keyword">this</span>.name = options.name;
}

bad = <span class="hljs-keyword">new</span> user({
    name: <span class="hljs-string">&apos;nope&apos;</span>
});
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> good = {};
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">User</span>(<span class="hljs-params">options</span>) </span>{
    <span class="hljs-keyword">this</span>.name = options.name;
}

good = <span class="hljs-keyword">new</span> User({
    name: <span class="hljs-string">&apos;yup&apos;</span>
});
</code></pre>
</li>
<li><p>&#x5982;&#x679C;&#x4F60;&#x7684;&#x6587;&#x4EF6;&#x5BFC;&#x51FA;&#x4E00;&#x4E2A;&#x7C7B;&#xFF0C;&#x4F60;&#x7684;&#x6587;&#x4EF6;&#x540D;&#x5E94;&#x8BE5;&#x4E0E;&#x7C7B;&#x540D;&#x5B8C;&#x5168;&#x76F8;&#x540C;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// file contents</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CheckBox</span> </span>{
  <span class="hljs-comment">// ...</span>
}
<span class="hljs-built_in">module</span>.exports = CheckBox;

<span class="hljs-comment">// in some other file</span>
<span class="hljs-keyword">var</span> CheckBox = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./checkBox&apos;</span>);

<span class="hljs-keyword">var</span> CheckBox = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./check_box&apos;</span>);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// file contents</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CheckBox</span> </span>{
  <span class="hljs-comment">// ...</span>
}
<span class="hljs-built_in">module</span>.exports = CheckBox;

<span class="hljs-comment">// in some other file</span>
<span class="hljs-keyword">var</span> CheckBox = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./CheckBox&apos;</span>);
</code></pre>
</li>
</ul>
<h1 id="&#x7A7A;&#x767D;"><a name="&#x7A7A;&#x767D;" class="anchor-navigation-ex-anchor" href="#&#x7A7A;&#x767D;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x7A7A;&#x767D;</h1>
<ul>
<li><p>&#x4F7F;&#x7528; 4 &#x4E2A;&#x7A7A;&#x683C;&#x4F5C;&#x4E3A;&#x7F29;&#x8FDB;&#xFF0C;&#x5E76;&#x4E14;&#x7981;&#x6B62;&#x628A;&#x7A7A;&#x683C;&#x548C;tab&#x952E;&#x6DF7;&#x7528;&#x6765;&#x8FDB;&#x884C;&#x7F29;&#x8FDB;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L93" target="_blank"><code>indent</code></a> eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L283" target="_blank"><code>no-mixed-spaces-and-tabs</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>) </span>{
&#x2219;&#x2219;<span class="hljs-keyword">var</span> name;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>) </span>{
&#x2219;<span class="hljs-keyword">var</span> name;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>) </span>{
&#x2219;&#x2219;&#x2219;&#x2219;<span class="hljs-keyword">var</span> name;
}
</code></pre>
</li>
<li><p>&#x5728;&#x5927;&#x62EC;&#x53F7;&#x524D;&#x653E;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L464" target="_blank"><code>space-before-blocks</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;test&apos;</span>);
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;test&apos;</span>);
}
</code></pre>
</li>
<li><p>&#x5728;JavaScript&#x7684;&#x5173;&#x952E;&#x5B57;&#xFF08;<code>if</code>&#x3001;<code>while</code>&#x7B49;&#xFF09;&#x540E;&#x8981;&#x653E;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002;&#x5728;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x65F6;&#xFF0C;&#x4E0D;&#x5728;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x5217;&#x8868;&#x524D;&#x52A0;&#x7A7A;&#x683C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L121" target="_blank"><code>keyword-spacing</code></a> eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L60" target="_blank">func-call-spacing</a> eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L334" target="_blank">no-spaced-func</a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> isJedi = <span class="hljs-literal">true</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fight</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log (<span class="hljs-string">&apos;Swooosh!&apos;</span>);
}
<span class="hljs-keyword">if</span>(isJedi) {
    fight ();
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> isJedi = <span class="hljs-literal">true</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fight</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Swooosh!&apos;</span>);
}
<span class="hljs-keyword">if</span> (isJedi) {
    fight();
}
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;&#x7A7A;&#x683C;&#x628A;&#x8FD0;&#x7B97;&#x7B26;&#x9694;&#x5F00;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L481" target="_blank"><code>space-infix-ops</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA=testB+<span class="hljs-number">5</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testB = testA + <span class="hljs-number">5</span>;
</code></pre>
</li>
<li><p>for&#x5FAA;&#x73AF;&#x5185;&#xFF0C;&#x5206;&#x53F7;&#x540E;&#x9762;&#x8981;&#x52A0;&#x4E0A;&#x7A7A;&#x683C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L446" target="_blank"><code>semi-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>;i &lt; <span class="hljs-number">10</span>;i++) {
    <span class="hljs-comment">// ...stuff...</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">10</span>; i++) {
    <span class="hljs-comment">// ...stuff...</span>
}
</code></pre>
</li>
<li><p>&#x5728;&#x6587;&#x4EF6;&#x672B;&#x5C3E;&#x63D2;&#x5165;&#x4E00;&#x4E2A;&#x7A7A;&#x884C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L520" target="_blank"><code>eol-last</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">global</span>) </span>{
    <span class="hljs-comment">// ...stuff...</span>
})(<span class="hljs-keyword">this</span>);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">global</span>) </span>{
    <span class="hljs-comment">// ...stuff...</span>
})(<span class="hljs-keyword">this</span>);&#x21B5;
&#x21B5;
</code></pre>
</li>
<li><p>&#x5728;&#x4EE3;&#x7801;&#x5757;&#x7684;&#x59CB;&#x672B;&#x548C;&#x65B0;&#x8BED;&#x53E5;&#x524D;&#x63D2;&#x5165;&#x7A7A;&#x884C;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x4EE3;&#x7801;&#x5757;&#x524D;&#x6DFB;&#x52A0;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L464" target="_blank"><code>space-before-blocks</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">if</span> (foo) {
        <span class="hljs-keyword">return</span> bar;
    }
  <span class="hljs-keyword">return</span> baz;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> obj = {

        foo: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
        },

        bar: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
        }

    };

    <span class="hljs-keyword">return</span> obj;
}
</code></pre>
</li>
<li><p>&#x907F;&#x514D;&#x5728;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x4E2D;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x7A7A;&#x683C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L73" target="_blank"><code>no-regex-spaces</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> reStr = <span class="hljs-regexp">/foo   bar/</span>;
<span class="hljs-keyword">var</span> reStr = <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">&apos;foo   bar&apos;</span>);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> reStr = <span class="hljs-regexp">/foo {3}bar/</span>;
<span class="hljs-keyword">var</span> reStr = <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">&apos;foo {3}bar&apos;</span>);
</code></pre>
</li>
<li><p>&#x5728;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x4E2D;&#xFF0C;&#x8981;&#x6C42;&#x952E;&#x540D;&#x4E0E;&#x5192;&#x53F7;&#x4E4B;&#x95F4;&#x6CA1;&#x6709;&#x7A7A;&#x683C;&#xFF0C;&#x5192;&#x53F7;&#x4E0E;&#x503C;&#x4E4B;&#x95F4;&#x6709;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L114" target="_blank"><code>key-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = { foo:<span class="hljs-number">42</span> };
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = { foo: <span class="hljs-number">42</span> };
</code></pre>
</li>
<li><p>&#x5728;&#x4E00;&#x5143;&#x5B57;&#x6BCD;&#x8FD0;&#x7B97;&#x7B26;&#x524D;&#x540E;&#x9700;&#x8981;&#x52A0;&#x7A7A;&#x683C;&#xFF0C;&#x5982;&#xFF1A;new&#xFF0C;delete&#xFF0C;typeof&#xFF0C;void&#xFF0C;yield&#x3002;&#x4E00;&#x5143;&#x8FD0;&#x7B97;&#x7B26;&#x5982;-&#xFF0C;+&#xFF0C;--&#xFF0C;++&#xFF0C;!&#xFF0C;!!&#x524D;&#x540E;&#x4E0D;&#x7528;&#x52A0;&#x7A7A;&#x683C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L114" target="_blank"><code>space-unary-ops</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">typeof</span>!foo;
<span class="hljs-keyword">void</span>{foo:<span class="hljs-number">0</span>};
<span class="hljs-keyword">new</span>[foo][<span class="hljs-number">0</span>];
<span class="hljs-keyword">delete</span>(foo.bar);
++ foo;
foo --;
- foo;
+ <span class="hljs-string">&apos;3&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">delete</span> foo.bar;
<span class="hljs-keyword">new</span> Foo;
<span class="hljs-keyword">void</span> <span class="hljs-number">0</span>;
++foo;
foo--;
-foo;
+<span class="hljs-string">&apos;3&apos;</span>;
</code></pre>
</li>
<li><p>&#x907F;&#x514D;&#x5728;&#x903B;&#x8F91;&#x8868;&#x8FBE;&#x5F0F;&#x3001;&#x6761;&#x4EF6;&#x8868;&#x8FBE;&#x5F0F;&#x3001;&#x58F0;&#x660E;&#x8BED;&#x53E5;&#x3001;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x3001;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x3001;&#x5E8F;&#x5217;&#x3001;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x4E2D;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x7A7A;&#x683C;&#xFF0C;&#x9664;&#x4E86;&#x8FDE;&#x7EED;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x7A7A;&#x683C;&#x7528;&#x4E8E;&#x7F29;&#x8FDB;&#x4EE5;&#x5916;&#xFF0C;&#x5176;&#x4ED6;&#x60C5;&#x51B5;&#x4E0B;&#x8FDE;&#x7EED;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x7A7A;&#x683C;&#x901A;&#x5E38;&#x662F;&#x9519;&#x8BEF;&#x7684;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L157" target="_blank"><code>no-multi-spaces</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item =  <span class="hljs-number">1</span>;
<span class="hljs-keyword">if</span>(foo   === <span class="hljs-string">&apos;bar&apos;</span>) {}
testA &lt;&lt;  testB;
<span class="hljs-keyword">var</span> arr = [<span class="hljs-number">1</span>,  <span class="hljs-number">2</span>];
testA ?   testB: testC;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item = <span class="hljs-number">1</span>;
<span class="hljs-keyword">if</span>(foo === <span class="hljs-string">&apos;bar&apos;</span>) {}
<span class="hljs-keyword">var</span> arr = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>];
testA ? testB : testC;
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x5728;&#x6570;&#x7EC4;&#x7684;&#x5DE6;&#x53F3;&#x65B9;&#x62EC;&#x53F7;&#x4E0E;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x4E4B;&#x95F4;&#x6709;&#x7A7A;&#x683C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L4" target="_blank"><code>array-bracket-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr = [ <span class="hljs-string">&apos;foo&apos;</span>, <span class="hljs-string">&apos;bar&apos;</span> ];
<span class="hljs-keyword">var</span> arr = [<span class="hljs-string">&apos;foo&apos;</span>, <span class="hljs-string">&apos;bar&apos;</span> ];
<span class="hljs-keyword">var</span> arr = [ [<span class="hljs-string">&apos;foo&apos;</span>], <span class="hljs-string">&apos;bar&apos;</span>];
<span class="hljs-keyword">var</span> arr = [[ <span class="hljs-string">&apos;foo&apos;</span> ], <span class="hljs-string">&apos;bar&apos;</span>];
<span class="hljs-keyword">var</span> arr = [ <span class="hljs-string">&apos;foo&apos;</span>,
  <span class="hljs-string">&apos;bar&apos;</span>
];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr = [];
<span class="hljs-keyword">var</span> arr = [<span class="hljs-string">&apos;foo&apos;</span>, <span class="hljs-string">&apos;bar&apos;</span>, <span class="hljs-string">&apos;baz&apos;</span>];
<span class="hljs-keyword">var</span> arr = [[<span class="hljs-string">&apos;foo&apos;</span>], <span class="hljs-string">&apos;bar&apos;</span>, <span class="hljs-string">&apos;baz&apos;</span>];
<span class="hljs-keyword">var</span> arr = [
  <span class="hljs-string">&apos;foo&apos;</span>,
  <span class="hljs-string">&apos;bar&apos;</span>,
  <span class="hljs-string">&apos;baz&apos;</span>
];
<span class="hljs-keyword">var</span> arr = [<span class="hljs-string">&apos;foo&apos;</span>,
  <span class="hljs-string">&apos;bar&apos;</span>
];
<span class="hljs-keyword">var</span> arr = [
  <span class="hljs-string">&apos;foo&apos;</span>,
  <span class="hljs-string">&apos;bar&apos;</span>];
</code></pre>
</li>
<li><p>&#x5355;&#x884C;&#x4EE3;&#x7801;&#x5757;&#x4E2D;&#xFF0C;&#x5757;&#x4E2D;&#x4EE3;&#x7801;&#x884C;&#x524D;&#x540E;&#x9700;&#x8981;&#x7559;&#x7A7A;&#x767D;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L8" target="_blank"><code>block-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;}
<span class="hljs-keyword">if</span> (foo) { bar = <span class="hljs-number">0</span>;}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">baz</span>(<span class="hljs-params"></span>) </span>{<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">return</span> i;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>; }
<span class="hljs-keyword">if</span> (foo) { bar = <span class="hljs-number">0</span>; }
</code></pre>
</li>
<li><p>&#x5206;&#x53F7;&#x524D;&#x9762;&#x4E0D;&#x5E94;&#x8BE5;&#x6709;&#x7A7A;&#x683C;&#xFF0C;&#x5206;&#x53F7;&#x540E;&#x9762;&#x6709;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L446" target="_blank"><code>semi-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">while</span> (item) { <span class="hljs-keyword">break</span> ; }
<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span> ; i &lt; <span class="hljs-number">10</span> ; i++) {}
<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>;i &lt; <span class="hljs-number">10</span>;i++) {}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">while</span> (item) { <span class="hljs-keyword">break</span>; }
<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">10</span>; i++) {}
<span class="hljs-keyword">for</span> (;;) {}
<span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {;}
</code></pre>
</li>
<li><p>&#x89C4;&#x5B9A;&#x9017;&#x53F7;&#x540E;&#x9762;&#x5E94;&#x8BE5;&#x7559;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L41" target="_blank"><code>comma-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">test,bar</span>) </span>{
    <span class="hljs-built_in">console</span>.log(test + bar);
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">test, bar</span>) </span>{
    <span class="hljs-built_in">console</span>.log(test + bar);
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x901A;&#x8FC7;[]&#x8BBF;&#x95EE;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x65F6;&#x65B9;&#x62EC;&#x53F7;&#x5185;&#x6709;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L52" target="_blank"><code>computed-property-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">obj[foo ];
obj[ <span class="hljs-string">&apos;foo&apos;</span>];
obj[foo[ bar ]];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">obj[foo];
obj[<span class="hljs-string">&apos;foo&apos;</span>];
obj[foo[bar]];
</code></pre>
</li>
<li><p>&#x4EE3;&#x7801;&#x4E2D;&#x6700;&#x591A;&#x8FDE;&#x7EED;&#x4F7F;&#x7528;&#x4E24;&#x884C;&#x7A7A;&#x884C;&#x3002;  eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L292" target="_blank"><code>no-multiple-empty-lines</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-number">5</span>;
&#x2219;&#x2219;&#x2219;&#x2219;
&#x2219;&#x2219;&#x2219;&#x2219;
&#x2219;&#x2219;&#x2219;&#x2219;
<span class="hljs-keyword">var</span> bar = <span class="hljs-number">3</span>;
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x4E09;&#x884C;&#x7A7A;&#x884C;</em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-number">5</span>;
&#x2219;&#x2219;&#x2219;&#x2219;
<span class="hljs-keyword">var</span> bar = <span class="hljs-number">3</span>;
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x4E00;&#x884C;&#x7A7A;&#x884C; &#x6216;&#x4E24;&#x884C;&#x7A7A;&#x884C;</em></p>
</li>
</ul>
<ul>
<li><p>&#x7981;&#x6B62;&#x884C;&#x672B;&#x5C3E;&#x6709;&#x7A7A;&#x683C;&#x3002;  eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L346" target="_blank"><code>no-trailing-spaces</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-number">0</span>;&#x2219;&#x2219;&#x2219;&#x2219;
<span class="hljs-keyword">var</span> baz = <span class="hljs-number">5</span>;&#x2219;
&#x2219;&#x2219;&#x2219;&#x2219;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-number">0</span>;
<span class="hljs-keyword">var</span> baz = <span class="hljs-number">5</span>;
</code></pre>
</li>
<li><p>&#x5982;&#x679C;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x4F4D;&#x4E8E;&#x540C;&#x4E00;&#x884C;&#xFF0C;&#x5219;&#x6B64;&#x89C4;&#x5219;&#x4E0D;&#x5141;&#x8BB8;&#x5728;&#x70B9;&#x5468;&#x56F4;&#x6216;&#x5F00;&#x59CB;&#x62EC;&#x53F7;&#x4E4B;&#x524D;&#x7684;&#x7A7A;&#x683C;&#x3002;&#x5F53;&#x5BF9;&#x8C61;&#x548C;&#x5C5E;&#x6027;&#x4F4D;&#x4E8E;&#x4E0D;&#x540C;&#x7684;&#x884C;&#x65F6;&#xFF0C;&#x6B64;&#x89C4;&#x5219;&#x5141;&#x8BB8;&#x4F7F;&#x7528;&#x7A7A;&#x683C;&#xFF0C;&#x56E0;&#x4E3A;&#x901A;&#x5E38;&#x5C06;&#x65B0;&#x884C;&#x6DFB;&#x52A0;&#x5230;&#x8F83;&#x957F;&#x7684;&#x5C5E;&#x6027;&#x94FE;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L364" target="_blank"><code>no-whitespace-before-property</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">foo [bar];
foo. bar;
foo .bar;
foo. bar. baz;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">foo.bar;
foo[bar];
foo.bar.baz;
foo
    .bar()
    .baz();
</code></pre>
</li>
<li><p>&#x89C4;&#x5B9A;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x4E2D;&#x5927;&#x62EC;&#x53F7;&#x5185;&#x90E8;&#x9700;&#x8981;&#x52A0;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L374" target="_blank"><code>object-curly-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = {<span class="hljs-string">&apos;foo&apos;</span>: <span class="hljs-string">&apos;bar&apos;</span>};
<span class="hljs-keyword">var</span> test = {<span class="hljs-string">&apos;foo&apos;</span>: <span class="hljs-string">&apos;bar&apos;</span> };
<span class="hljs-keyword">var</span> item = { baz: {<span class="hljs-string">&apos;foo&apos;</span>: <span class="hljs-string">&apos;qux&apos;</span>}};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = {};
<span class="hljs-keyword">var</span> test = { <span class="hljs-string">&apos;foo&apos;</span>: <span class="hljs-string">&apos;bar&apos;</span> };
<span class="hljs-keyword">var</span> item = { <span class="hljs-string">&apos;foo&apos;</span>: { <span class="hljs-string">&apos;bar&apos;</span>: <span class="hljs-string">&apos;baz&apos;</span> }, <span class="hljs-string">&apos;qux&apos;</span>: <span class="hljs-string">&apos;quxx&apos;</span> };
</code></pre>
</li>
<li><p>&#x4E0D;&#x5141;&#x8BB8;&#x5728;(&#x53F3;&#x8FB9;&#xFF0C;&#x6216;&#x8005;)&#x5DE6;&#x8FB9;&#x52A0;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L477" target="_blank"><code>space-in-parens</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">foo( <span class="hljs-string">&apos;bar&apos;</span>);
foo(<span class="hljs-string">&apos;bar&apos;</span> );
foo( <span class="hljs-string">&apos;bar&apos;</span> );
<span class="hljs-keyword">var</span> foo = ( <span class="hljs-number">1</span> + <span class="hljs-number">2</span> ) * <span class="hljs-number">3</span>;
( <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;bar&apos;</span>; }() );
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">foo();
foo(<span class="hljs-string">&apos;bar&apos;</span>);
<span class="hljs-keyword">var</span> foo = (<span class="hljs-number">1</span> + <span class="hljs-number">2</span>) * <span class="hljs-number">3</span>;
(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;bar&apos;</span>; }());
</code></pre>
</li>
<li><p>&#x4EE3;&#x7801;&#x6CE8;&#x91CA;&#x7B26;&#x53F7;&#x540E;&#x9762;&#x8981;&#x52A0;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L494" target="_blank"><code>spaced-comment</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">//This is a comment with no whitespace at the beginning</span>

<span class="hljs-comment">/*This is a comment with no whitespace at the beginning */</span>
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// This is a comment with a whitespace at the beginning</span>

<span class="hljs-comment">/* This is a comment with a whitespace at the beginning */</span>
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;tab&#x952E;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L338" target="_blank"><code>no-tabs</code></a></p>
</li>
</ul>
<h1 id="&#x9017;&#x53F7;"><a name="&#x9017;&#x53F7;" class="anchor-navigation-ex-anchor" href="#&#x9017;&#x53F7;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x9017;&#x53F7;</h1>
<ul>
<li><p>&#x884C;&#x9996;&#x9017;&#x53F7;: <strong>&#x4E0D;&#x9700;&#x8981;</strong>&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L48" target="_blank"><code>comma-style</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> story = [
    once
    , upon
    , aTime
];

<span class="hljs-keyword">var</span> hero = {
    firstName: <span class="hljs-string">&apos;Bob&apos;</span>
    , lastName: <span class="hljs-string">&apos;Parr&apos;</span>
    , heroName: <span class="hljs-string">&apos;Mr. Incredible&apos;</span>
    , superPower: <span class="hljs-string">&apos;strength&apos;</span>
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> story = [
    once,
    upon,
    aTime
];

<span class="hljs-keyword">var</span> hero = {
    firstName: <span class="hljs-string">&apos;Bob&apos;</span>,
    lastName: <span class="hljs-string">&apos;Parr&apos;</span>,
    heroName: <span class="hljs-string">&apos;Mr. Incredible&apos;</span>,
    superPower: <span class="hljs-string">&apos;strength&apos;</span>
};
</code></pre>
</li>
<li><p>&#x989D;&#x5916;&#x7684;&#x884C;&#x672B;&#x9017;&#x53F7;&#xFF1A;<strong>&#x4E0D;&#x9700;&#x8981;</strong>&#x3002;&#x8FD9;&#x6837;&#x505A;&#x4F1A;&#x5728; IE6/7 &#x548C; IE9 &#x602A;&#x5F02;&#x6A21;&#x5F0F;&#x4E0B;&#x5F15;&#x8D77;&#x95EE;&#x9898;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L3" target="_blank"><code>comma-dangle</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> hero = {
    firstName: <span class="hljs-string">&apos;Kevin&apos;</span>,
    lastName: <span class="hljs-string">&apos;Flynn&apos;</span>,
};

<span class="hljs-keyword">var</span> heroes = [
    <span class="hljs-string">&apos;Batman&apos;</span>,
    <span class="hljs-string">&apos;Superman&apos;</span>,
];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> hero = {
    firstName: <span class="hljs-string">&apos;Kevin&apos;</span>,
    lastName: <span class="hljs-string">&apos;Flynn&apos;</span>
};

<span class="hljs-keyword">var</span> heroes = [
    <span class="hljs-string">&apos;Batman&apos;</span>,
    <span class="hljs-string">&apos;Superman&apos;</span>
];
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x9017;&#x53F7;&#x6765;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x7A7A;&#x6570;&#x7EC4;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L76" target="_blank"><code>no-sparse-arrays</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> items = [,];
<span class="hljs-keyword">var</span> colors = [<span class="hljs-string">&apos;red&apos;</span>,, <span class="hljs-string">&apos;blue&apos;</span>];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> items = [];
<span class="hljs-keyword">var</span> colors = [<span class="hljs-string">&apos;red&apos;</span>, <span class="hljs-string">&apos;blue&apos;</span>];
</code></pre>
</li>
<li><p>&#x907F;&#x514D;&#x4F7F;&#x7528;&#x9017;&#x53F7;&#x64CD;&#x4F5C;&#x7B26;,&#x5728;for&#x8BED;&#x53E5;&#x7684;&#x521D;&#x59CB;&#x5316;&#x6216;&#x66F4;&#x65B0;&#x90E8;&#x5206;&#x6216;&#x5982;&#x679C;&#x8868;&#x8FBE;&#x5F0F;&#x5E8F;&#x5217;&#x660E;&#x786E;&#x5730;&#x5305;&#x542B;&#x5728;&#x62EC;&#x53F7;&#x4E2D;&#x65F6;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x9017;&#x53F7;&#x8FD0;&#x7B97;&#x7B26;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L242" target="_blank"><code>no-sequences</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">5</span>;
<span class="hljs-keyword">var</span> testB = <span class="hljs-number">0</span>;
testA = testB += <span class="hljs-number">5</span>, testA + testB;
<span class="hljs-keyword">while</span> (testA = next(), testA &amp;&amp; testA.length);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">foo = (doSomething(), val);
(<span class="hljs-number">0</span>, <span class="hljs-built_in">eval</span>)(<span class="hljs-string">&quot;doSomething();&quot;</span>);
<span class="hljs-keyword">do</span> {} <span class="hljs-keyword">while</span> ((doSomething(), !!test));
<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>, j = <span class="hljs-number">10</span>; i &lt; j; i++, j--);
</code></pre>
</li>
</ul>
<h1 id="&#x5206;&#x53F7;"><a name="&#x5206;&#x53F7;" class="anchor-navigation-ex-anchor" href="#&#x5206;&#x53F7;"><i class="fa fa-link" aria-hidden="true"></i></a>4. &#x5206;&#x53F7;</h1>
<ul>
<li><p>JavaScript &#x7684;&#x8BED;&#x53E5;&#x4EE5;&#x5206;&#x53F7;&#x4F5C;&#x4E3A;&#x7ED3;&#x675F;&#x7B26;&#xFF0C;&#x7981;&#x6B62;&#x7701;&#x7565;&#x5206;&#x53F7;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L79" target="_blank"><code>no-unexpected-multiline</code></a> eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L442" target="_blank"><code>semi</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> name = <span class="hljs-string">&apos;Skywalker&apos;</span>
    <span class="hljs-keyword">return</span> name
}())
<span class="hljs-keyword">var</span> foo = bar
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> name = <span class="hljs-string">&apos;Skywalker&apos;</span>;
    <span class="hljs-keyword">return</span> name;
}());

;(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> name = <span class="hljs-string">&apos;Skywalker&apos;</span>;
    <span class="hljs-keyword">return</span> name;
}());
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x9632;&#x6B62;&#x51FD;&#x6570;&#x5728;&#x4E24;&#x4E2A; IIFE &#x5408;&#x5E76;&#x65F6;&#x88AB;&#x5F53;&#x6210;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x3002;</em></p>
</li>
</ul>
<ul>
<li><p>&#x4E0D;&#x5141;&#x8BB8;&#x4F7F;&#x7528;&#x591A;&#x4F59;&#x7684;&#x5206;&#x53F7;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L55" target="_blank"><code>no-extra-semi</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item = <span class="hljs-number">5</span>;;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// code</span>
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item = <span class="hljs-number">5</span>;
<span class="hljs-keyword">var</span> foo = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// code</span>
};
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// code</span>
}
</code></pre>
</li>
</ul>
<h1 id="&#x53D8;&#x91CF;"><a name="&#x53D8;&#x91CF;" class="anchor-navigation-ex-anchor" href="#&#x53D8;&#x91CF;"><i class="fa fa-link" aria-hidden="true"></i></a>5. &#x53D8;&#x91CF;</h1>
<ul>
<li><p>&#x53D8;&#x91CF;&#x7684;&#x540D;&#x79F0;&#x91C7;&#x7528;&#x9A7C;&#x5CF0;&#x6CD5;&#x5219;&#xFF0C;&#x9996;&#x5B57;&#x6BCD;&#x5C0F;&#x5199;&#xFF0C;&#x540E;&#x7EED;&#x5355;&#x8BCD;&#x7684;&#x9996;&#x5B57;&#x6BCD;&#x5927;&#x5199;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L19" target="_blank"><code>camelcase</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> Is_Editable = <span class="hljs-literal">false</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> isEditable = <span class="hljs-literal">false</span>;
</code></pre>
</li>
<li><p>&#x603B;&#x662F;&#x4F7F;&#x7528; <code>var</code> &#x6765;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x3002;&#x4E0D;&#x8FD9;&#x4E48;&#x505A;&#x5C06;&#x5BFC;&#x81F4;&#x4EA7;&#x751F;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;&#x6211;&#x4EEC;&#x8981;&#x907F;&#x514D;&#x6C61;&#x67D3;&#x5168;&#x5C40;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/variables.js#L32" target="_blank"><code>no-undef</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">superPower = <span class="hljs-keyword">new</span> SuperPower();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> superPower = <span class="hljs-keyword">new</span> SuperPower();
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528; <code>var</code> &#x58F0;&#x660E;&#x6BCF;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x5E76;&#x4E14;&#x6BCF;&#x884C;&#x53EA;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x3002;&#x8FD9;&#x6837;&#x505A;&#x7684;&#x597D;&#x5904;&#x662F;&#x589E;&#x52A0;&#x65B0;&#x53D8;&#x91CF;&#x5C06;&#x53D8;&#x7684;&#x66F4;&#x52A0;&#x5BB9;&#x6613;&#xFF0C;&#x800C;&#x4E14;&#x4F60;&#x6C38;&#x8FDC;&#x4E0D;&#x7528;&#x518D;&#x62C5;&#x5FC3;&#x8C03;&#x6362;&#x9519; <code>;</code> &#x8DDF; <code>,</code>&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L400" target="_blank"><code>one-var</code></a> eslint:<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L404" target="_blank"><code>one-var-declaration-per-line</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> items = getItems(),
    goSportsTeam = <span class="hljs-literal">true</span>,
    dragonball = <span class="hljs-string">&apos;z&apos;</span>;
<span class="hljs-keyword">var</span> foo = <span class="hljs-number">1</span>, bar = <span class="hljs-number">2</span>;

<span class="hljs-keyword">var</span> items = getItems(),
    goSportsTeam = <span class="hljs-literal">true</span>;
    dragonball = <span class="hljs-string">&apos;z&apos;</span>;
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x8DDF;&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x6BD4;&#x8F83;&#x4E00;&#x4E0B;&#xFF0C;&#x770B;&#x770B;&#x54EA;&#x91CC;&#x9519;&#x4E86;&#x3002;</em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> items = getItems();
<span class="hljs-keyword">var</span> goSportsTeam = <span class="hljs-literal">true</span>;
<span class="hljs-keyword">var</span> dragonball = <span class="hljs-string">&apos;z&apos;</span>;
</code></pre>
</li>
<li><p>&#x6700;&#x540E;&#x518D;&#x58F0;&#x660E;&#x672A;&#x8D4B;&#x503C;&#x7684;&#x53D8;&#x91CF;&#x3002;&#x5F53;&#x4F60;&#x9700;&#x8981;&#x5F15;&#x7528;&#x524D;&#x9762;&#x7684;&#x53D8;&#x91CF;&#x8D4B;&#x503C;&#x65F6;&#x8FD9;&#x5C06;&#x53D8;&#x7684;&#x5F88;&#x6709;&#x7528;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> i, len, dragonball,
    items = getItems(),
    goSportsTeam = <span class="hljs-literal">true</span>;

<span class="hljs-keyword">var</span> i;
<span class="hljs-keyword">var</span> items = getItems();
<span class="hljs-keyword">var</span> dragonball;
<span class="hljs-keyword">var</span> goSportsTeam = <span class="hljs-literal">true</span>;
<span class="hljs-keyword">var</span> len;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> items = getItems();
<span class="hljs-keyword">var</span> goSportsTeam = <span class="hljs-literal">true</span>;
<span class="hljs-keyword">var</span> dragonball;
<span class="hljs-keyword">var</span> length;
<span class="hljs-keyword">var</span> i;
</code></pre>
</li>
<li><p>&#x5728;&#x4F5C;&#x7528;&#x57DF;&#x9876;&#x90E8;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x3002;&#x8FD9;&#x5C06;&#x5E2E;&#x4F60;&#x907F;&#x514D;&#x53D8;&#x91CF;&#x58F0;&#x660E;&#x63D0;&#x5347;&#x76F8;&#x5173;&#x7684;&#x95EE;&#x9898;&#x3002;&#x4FDD;&#x8BC1;&#x5728;&#x4EE3;&#x7801;&#x5757;&#x7684;&#x9876;&#x90E8;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L61" target="_blank"><code>no-inner-declarations</code></a> eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L320" target="_blank"><code>vars-on-top</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    test();
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;doing stuff..&apos;</span>);

    <span class="hljs-comment">// ..other stuff..</span>
    <span class="hljs-keyword">var</span> name = getName();
    <span class="hljs-keyword">if</span> (name === <span class="hljs-string">&apos;test&apos;</span>) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-keyword">return</span> name;
}
<span class="hljs-keyword">if</span> (test) {
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomethingElse</span> (<span class="hljs-params"></span>) </span>{ }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> name = getName();

    <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">arguments</span>.length) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-keyword">this</span>.setFirstName(name);

    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
}
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x3002;</em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> name = getName();
    test();
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;doing stuff..&apos;</span>);

    <span class="hljs-comment">// ..other stuff..</span>
    <span class="hljs-keyword">if</span> (name === <span class="hljs-string">&apos;test&apos;</span>) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-keyword">return</span> name;
}
<span class="hljs-keyword">if</span> (test) {
    foo();
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> name;

    <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">arguments</span>.length) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    name = getName();
    <span class="hljs-keyword">this</span>.setFirstName(name);

    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x91CD;&#x590D;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L198" target="_blank"><code>no-redeclar</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">3</span>;
<span class="hljs-keyword">var</span> testA = <span class="hljs-number">10</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">3</span>;
testA = <span class="hljs-number">10</span>;
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4FEE;&#x6539;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#x6216;&#x53EA;&#x8BFB;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L98" target="_blank"><code>no-global-assign</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-built_in">Object</span> = <span class="hljs-literal">null</span>;
<span class="hljs-literal">undefined</span> = <span class="hljs-number">1</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">1</span>;
<span class="hljs-keyword">var</span> testB = <span class="hljs-number">1</span>;
testB = <span class="hljs-number">2</span>;
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x5728;&#x5FAA;&#x73AF;&#x8BED;&#x53E5;&#x4E2D;&#x7F16;&#x5199;&#x51FD;&#x6570;&#x3002;&#x7531;&#x4E8E;&#x51FD;&#x6570;&#x5728;&#x5FAA;&#x73AF;&#x5468;&#x56F4;&#x521B;&#x5EFA;&#x95ED;&#x5305;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x5728;&#x5FAA;&#x73AF;&#x4E2D;&#x7F16;&#x5199;&#x51FD;&#x6570;&#x5F80;&#x5F80;&#x4F1A;&#x5BFC;&#x81F4;&#x9519;&#x8BEF;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L143" target="_blank"><code>no-loop-func</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> data = [];
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">10</span>; i; i--) {
    data[i] = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> i; };
}
data[<span class="hljs-number">0</span>]();
data[<span class="hljs-number">1</span>]();
data[<span class="hljs-number">2</span>]();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> itemFunc = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">t</span>) </span>{ <span class="hljs-built_in">console</span>.log(t) };
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">10</span>; i; i--) {
    itemFunc(i);
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x5C24;&#x8FBE;&#x6761;&#x4EF6;&#xFF0C;&#x5C24;&#x8FBE;&#x6761;&#x4EF6;&#x8BED;&#x53E5;&#x5C31;&#x662F;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x5199;&#x5728;&#x6BD4;&#x8F83;&#x64CD;&#x4F5C;&#x7B26;&#x7684;&#x5DE6;&#x8FB9;&#xFF0C;&#x800C;&#x53D8;&#x91CF;&#x5E94;&#x8BE5;&#x5199;&#x5728;&#x6BD4;&#x8F83;&#x64CD;&#x4F5C;&#x7B26;&#x7684;&#x53F3;&#x8FB9;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L331" target="_blank"><code>yoda</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (<span class="hljs-string">&apos;red&apos;</span> === color) {
    <span class="hljs-comment">// ...</span>
}
<span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span> === flag) {
    <span class="hljs-comment">// ...</span>
}
<span class="hljs-keyword">if</span> (<span class="hljs-number">5</span> &gt; count) {
    <span class="hljs-comment">// ...</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (flag === <span class="hljs-literal">true</span>) {
    <span class="hljs-comment">// ...</span>
}
<span class="hljs-keyword">if</span> (value === <span class="hljs-string">&apos;red&apos;</span>) {
    <span class="hljs-comment">// ...</span>
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x7528;delete&#x5220;&#x9664;var&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#xFF0C;delete&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x76EE;&#x7684;&#x662F;&#x4ECE;&#x5BF9;&#x8C61;&#x4E2D;&#x5220;&#x9664;&#x5C5E;&#x6027;&#x3002;delete&#x5728;&#x53D8;&#x91CF;&#x4E0A;&#x4F7F;&#x7528;&#x8FD0;&#x7B97;&#x7B26;&#x53EF;&#x80FD;&#x4F1A;&#x5BFC;&#x81F4;&#x610F;&#x5916;&#x884C;&#x4E3A;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/variables.js#L11" target="_blank"><code>no-delete-var</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> test;
<span class="hljs-keyword">delete</span> test;
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x521B;&#x5EFA;&#x4E0E;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x7684;&#x53D8;&#x91CF;&#x5171;&#x4EAB;&#x540D;&#x79F0;&#x7684;&#x6807;&#x7B7E;&#x7684;&#x4E0D;&#x826F;&#x505A;&#x6CD5;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/variables.js#L15" target="_blank"><code>no-label-var</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item = foo;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>) </span>{
  item:
    <span class="hljs-keyword">for</span> (;;) {
        <span class="hljs-keyword">break</span> item;
    }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> item = <span class="hljs-string">&apos;foo&apos;</span>;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">for</span> (;;) {
        <span class="hljs-keyword">break</span>;
    }
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x4E0E;&#x5916;&#x5C42;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x53D8;&#x91CF;&#x540C;&#x540D;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/variables.js#L24" target="_blank"><code>no-shadow</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item = <span class="hljs-number">3</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> item = <span class="hljs-number">10</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item = <span class="hljs-number">3</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> count = <span class="hljs-number">10</span>;
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x65F6;&#x8986;&#x76D6;JavaScript&#x4E2D;&#x7684;&#x4FDD;&#x7559;&#x5173;&#x952E;&#x5B57;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/variables.js#L28" target="_blank"><code>no-shadow-restricted-names</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">NaN</span>(<span class="hljs-params"></span>)</span>{}
!<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">Infinity</span>)</span>{};
<span class="hljs-keyword">var</span> <span class="hljs-literal">undefined</span> = <span class="hljs-number">5</span>;
<span class="hljs-keyword">try</span> {} <span class="hljs-keyword">catch</span>(<span class="hljs-built_in">eval</span>){}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> test;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">testFunc</span>(<span class="hljs-params">index, val</span>) </span>{}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x6CA1;&#x6709;&#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/variables.js#L32" target="_blank"><code>no-undef</code></a> eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/variables.js#L54" target="_blank"><code>no-use-before-define</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">5</span>;
testB = <span class="hljs-number">10</span>;
testFunc();
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">testFunc</span>(<span class="hljs-params"></span>) </span>{}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">5</span>;
testA = <span class="hljs-number">10</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">testFunc</span>(<span class="hljs-params"></span>) </span>{}
testFunc();
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x5C06;&#x53D8;&#x91CF;&#x521D;&#x59CB;&#x5316;&#x4E3A;undefined&#xFF0C;&#x5728;JavaScript&#x4E2D;&#xFF0C;&#x58F0;&#x660E;&#x4F46;&#x672A;&#x521D;&#x59CB;&#x5316;&#x4E3A;&#x4EFB;&#x4F55;&#x503C;&#x7684;&#x53D8;&#x91CF;&#x4F1A;&#x81EA;&#x52A8;&#x83B7;&#x53D6;&#x503C;undefined&#xFF0C;&#x56E0;&#x6B64;&#x4E0D;&#x5FC5;&#x5C06;&#x53D8;&#x91CF;&#x521D;&#x59CB;&#x5316;&#x4E3A;undefined&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/variables.js#L36" target="_blank"><code>no-undef-init</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-literal">undefined</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo;
</code></pre>
</li>
<li><p>&#x4E0D;&#x5141;&#x8BB8;&#x5B9A;&#x4E49;&#x4E86;&#x7684;&#x53D8;&#x91CF;&#x4F46;&#x662F;&#x5728;&#x540E;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x4E2D;&#x6CA1;&#x6709;&#x88AB;&#x4F7F;&#x7528;&#x5230;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/variables.js#L46" target="_blank"><code>no-unused-vars</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">item</span>) </span>{
    <span class="hljs-keyword">var</span> count = <span class="hljs-number">10</span>;
    <span class="hljs-keyword">var</span> len = <span class="hljs-number">0</span>;
    <span class="hljs-built_in">console</span>.log(count);
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">item</span>) </span>{
    <span class="hljs-built_in">console</span>.log(item);
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x94FE;&#x5F0F;&#x8D4B;&#x503C;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L287" target="_blank"><code>no-multi-assign</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = testB = testC = <span class="hljs-number">5</span>;
<span class="hljs-keyword">var</span> foo = bar = <span class="hljs-string">&apos;baz&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">5</span>;
<span class="hljs-keyword">var</span> testB = <span class="hljs-number">5</span>;
<span class="hljs-keyword">var</span> testC = <span class="hljs-number">5</span>;
<span class="hljs-keyword">var</span> foo = <span class="hljs-string">&apos;baz&apos;</span>;
<span class="hljs-keyword">var</span> bar = <span class="hljs-string">&apos;baz&apos;</span>;
</code></pre>
</li>
</ul>
<h1 id="&#x5BF9;&#x8C61;"><a name="&#x5BF9;&#x8C61;" class="anchor-navigation-ex-anchor" href="#&#x5BF9;&#x8C61;"><i class="fa fa-link" aria-hidden="true"></i></a>6. &#x5BF9;&#x8C61;</h1>
<ul>
<li><p>&#x4F7F;&#x7528;&#x76F4;&#x63A5;&#x91CF;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L308" target="_blank"><code>no-new-object</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Object</span>();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item = {};
</code></pre>
</li>
<li><p>&#x5728;&#x4F7F;&#x7528;&#x957F;&#x65B9;&#x6CD5;&#x94FE;&#x65F6;&#x8FDB;&#x884C;&#x7F29;&#x8FDB;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;&#x524D;&#x9762;&#x7684;&#x70B9; <code>.</code> &#x5F3A;&#x8C03;&#x8FD9;&#x662F;&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x800C;&#x4E0D;&#x662F;&#x65B0;&#x8BED;&#x53E5;&#x3002;&#x5728;&#x4F7F;&#x7528;<code>.</code>&#x53F7;&#x8C03;&#x7528;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x65F6;&#xFF0C;&#x5E94;&#x4FDD;&#x6301;<code>.</code>&#x53F7;&#x4E0E;&#x5C5E;&#x6027;&#x5728;&#x540C;&#x4E00;&#x884C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L23" target="_blank"><code>dot-location</code></a> eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L238" target="_blank"><code>newline-per-chained-call</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">$(<span class="hljs-string">&apos;#items&apos;</span>).find(<span class="hljs-string">&apos;.selected&apos;</span>).highlight().end().find(<span class="hljs-string">&apos;.open&apos;</span>).updateCount();
<span class="hljs-keyword">var</span> foo = object.
        property;

$(<span class="hljs-string">&apos;#items&apos;</span>).
    find(<span class="hljs-string">&apos;.selected&apos;</span>).
    highlight().
    end().
    find(<span class="hljs-string">&apos;.open&apos;</span>).
    updateCount();

<span class="hljs-keyword">var</span> leds = stage.selectAll(<span class="hljs-string">&apos;.led&apos;</span>).data(data).enter().append(<span class="hljs-string">&apos;svg:svg&apos;</span>).classed(<span class="hljs-string">&apos;led&apos;</span>, <span class="hljs-literal">true</span>)
    .attr(<span class="hljs-string">&apos;width&apos;</span>, (radius + margin) * <span class="hljs-number">2</span>).append(<span class="hljs-string">&apos;svg:g&apos;</span>)
    .attr(<span class="hljs-string">&apos;transform&apos;</span>, <span class="hljs-string">&apos;translate(&apos;</span> + (radius + margin) + <span class="hljs-string">&apos;,&apos;</span> + (radius + margin) + <span class="hljs-string">&apos;)&apos;</span>)
    .call(tron.led);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">$(<span class="hljs-string">&apos;#items&apos;</span>)
    .find(<span class="hljs-string">&apos;.selected&apos;</span>)
    .highlight()
    .end()
    .find(<span class="hljs-string">&apos;.open&apos;</span>)
    .updateCount();
<span class="hljs-keyword">var</span> foo = object.property;

<span class="hljs-keyword">var</span> leds = stage.selectAll(<span class="hljs-string">&apos;.led&apos;</span>)
    .data(data)
    .enter().append(<span class="hljs-string">&apos;svg:svg&apos;</span>)
    .classed(<span class="hljs-string">&apos;led&apos;</span>, <span class="hljs-literal">true</span>)
    .attr(<span class="hljs-string">&apos;width&apos;</span>, (radius + margin) * <span class="hljs-number">2</span>)
    .append(<span class="hljs-string">&apos;svg:g&apos;</span>)
    .attr(<span class="hljs-string">&apos;transform&apos;</span>, <span class="hljs-string">&apos;translate(&apos;</span> + (radius + margin) + <span class="hljs-string">&apos;,&apos;</span> + (radius + margin) + <span class="hljs-string">&apos;)&apos;</span>)
    .call(tron.led);
</code></pre>
</li>
<li><p>&#x4E0D;&#x5141;&#x8BB8;&#x5728;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x7533;&#x660E;&#x5BF9;&#x8C61;&#x7684;&#x65F6;&#x4F7F;&#x7528;&#x76F8;&#x540C;&#x7684;&#x952E;&#x540D;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L24" target="_blank"><code>no-dupe-keys</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = {
    bar: <span class="hljs-string">&apos;baz&apos;</span>,
    bar: <span class="hljs-string">&apos;qux&apos;</span>
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = {
    bar: <span class="hljs-string">&apos;baz&apos;</span>,
    quxx: <span class="hljs-string">&apos;qux&apos;</span>
};
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x5C06;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#xFF08;Math&#x548C;JSON)&#x4F5C;&#x4E3A;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L70" target="_blank"><code>no-obj-calls</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> math = <span class="hljs-built_in">Math</span>();
<span class="hljs-keyword">var</span> json = <span class="hljs-built_in">JSON</span>();
<span class="hljs-keyword">var</span> reflect = <span class="hljs-built_in">Reflect</span>();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">area</span>(<span class="hljs-params">r</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Math</span>.PI * r * r;
}
<span class="hljs-keyword">var</span> object = <span class="hljs-built_in">JSON</span>.parse(<span class="hljs-string">&quot;{}&quot;</span>);
<span class="hljs-keyword">var</span> value = <span class="hljs-built_in">Reflect</span>.get({ x: <span class="hljs-number">1</span>, y: <span class="hljs-number">2</span> }, <span class="hljs-string">&quot;x&quot;</span>);
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x7279;&#x5B9A;&#x5BF9;&#x8C61;&#x7684;&#x6307;&#x5B9A;&#x65B9;&#x6CD5;&#xFF0C;&#x6709;arguments&#x7684;callee&#x65B9;&#x6CD5;&#x3001;Math&#x7684;pow&#x65B9;&#x6CD5;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L202" target="_blank"><code>no-restricted-properties</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> example = <span class="hljs-built_in">Math</span>.pow(<span class="hljs-number">4</span>, <span class="hljs-number">3</span>);
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">calleeDemo</span>(<span class="hljs-params"></span>) </span>{
    alert(<span class="hljs-built_in">arguments</span>.callee);
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> example = <span class="hljs-number">4</span> ** <span class="hljs-number">3</span>;
[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>].map(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">factorial</span>(<span class="hljs-params">n</span>) </span>{
    <span class="hljs-keyword">return</span> !(n &gt; <span class="hljs-number">1</span>) ? <span class="hljs-number">1</span> : factorial(n - <span class="hljs-number">1</span>) * n;
});
</code></pre>
</li>
<li><p>&#x4E0D;&#x8981;&#x4F7F;&#x7528;<a href="http://es5.github.io/#x7.6.1" target="_blank">&#x4FDD;&#x7559;&#x5B57;</a>&#x4F5C;&#x4E3A;&#x952E;&#x540D;&#xFF0C;&#x5B83;&#x4EEC;&#x5728; IE8 &#x4E0B;&#x4E0D;&#x5DE5;&#x4F5C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/variables.js#L28" target="_blank"><code>no-shadow-restricted-names</code></a></p>
</li>
</ul>
<h1 id="&#x6570;&#x7EC4;"><a name="&#x6570;&#x7EC4;" class="anchor-navigation-ex-anchor" href="#&#x6570;&#x7EC4;"><i class="fa fa-link" aria-hidden="true"></i></a>7. &#x6570;&#x7EC4;</h1>
<ul>
<li><p>&#x4F7F;&#x7528;&#x76F4;&#x63A5;&#x91CF;&#x521B;&#x5EFA;&#x6570;&#x7EC4;&#x3002; &#x7981;&#x6B62;&#x4F7F;&#x7528;new&#x521B;&#x5EFA;&#x5305;&#x88C5;&#x5B9E;&#x4F8B;&#xFF0C;&#x5982; new String&#x3001;new Number&#xFF0C;&#x8FD9;&#x6837;&#x4F1A;&#x53D8;&#x6210;&#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x5BF9;&#x5E94;&#x7684;&#x521D;&#x59CB;&#x7C7B;&#x578B;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L169" target="_blank"><code>no-new-wrappers</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> items = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> items = [];
</code></pre>
</li>
<li><p>&#x5411;&#x6570;&#x7EC4;&#x589E;&#x52A0;&#x5143;&#x7D20;&#x65F6;&#x4F7F;&#x7528; Array#push &#x6765;&#x66FF;&#x4EE3;&#x76F4;&#x63A5;&#x8D4B;&#x503C;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">someStack[someStack.length] = <span class="hljs-string">&apos;abracadabra&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">someStack.push(<span class="hljs-string">&apos;abracadabra&apos;</span>);
</code></pre>
</li>
<li><p>&#x5F53;&#x4F60;&#x9700;&#x8981;&#x62F7;&#x8D1D;&#x6570;&#x7EC4;&#x65F6;&#xFF0C;&#x4F7F;&#x7528; Array#slice&#x3002;<a href="http://jsperf.com/converting-arguments-to-an-array/7" target="_blank">jsPerf</a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-keyword">var</span> len = items.length;
<span class="hljs-keyword">var</span> itemsCopy = [];
<span class="hljs-keyword">var</span> i;

<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i &lt; len; i++) {
    itemsCopy[i] = items[i];
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-keyword">var</span> len = items.length;
<span class="hljs-keyword">var</span> itemsCopy = [];
<span class="hljs-keyword">var</span> i;

itemsCopy = items.slice();
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528; Array#slice &#x5C06;&#x7C7B;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;&#x8F6C;&#x6362;&#x6210;&#x6570;&#x7EC4;&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">trigger</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> args = <span class="hljs-built_in">Array</span>.prototype.slice.call(<span class="hljs-built_in">arguments</span>);
  ...
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;Array&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L246" target="_blank"><code>no-array-constructor</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = [];
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;for-in&#x8BED;&#x53E5;&#x679A;&#x4E3E;&#x6570;&#x7EC4;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> list = [<span class="hljs-number">8</span>, <span class="hljs-number">3</span>, <span class="hljs-number">11</span>, <span class="hljs-number">9</span>, <span class="hljs-number">6</span>]
<span class="hljs-keyword">for</span> (i <span class="hljs-keyword">in</span> list) {
    <span class="hljs-built_in">console</span>.log(list[i]);
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj={
   one:<span class="hljs-string">&apos;first&apos;</span>,
   two:<span class="hljs-string">&apos;zoo&apos;</span>,
   three:<span class="hljs-string">&apos;34&apos;</span>
};
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> key <span class="hljs-keyword">in</span> obj) {
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">Object</span>.prototype.hasOwnProperty.call(obj, key)) {
        <span class="hljs-built_in">console</span>.log(key+<span class="hljs-string">&apos;:&apos;</span>+obj[key]);
    }
};
</code></pre>
</li>
</ul>
<h1 id="&#x5B57;&#x7B26;&#x4E32;"><a name="&#x5B57;&#x7B26;&#x4E32;" class="anchor-navigation-ex-anchor" href="#&#x5B57;&#x7B26;&#x4E32;"><i class="fa fa-link" aria-hidden="true"></i></a>8. &#x5B57;&#x7B26;&#x4E32;</h1>
<ul>
<li><p>&#x4F7F;&#x7528;&#x5355;&#x5F15;&#x53F7; <code>&apos;&apos;</code> &#x5305;&#x88F9;&#x5B57;&#x7B26;&#x4E32;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L431" target="_blank"><code>quotes</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> name = <span class="hljs-string">&quot;Bob Parr&quot;</span>;

<span class="hljs-keyword">var</span> fullName = <span class="hljs-string">&quot;Bob &quot;</span> + <span class="hljs-keyword">this</span>.lastName;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> name = <span class="hljs-string">&apos;Bob Parr&apos;</span>;

<span class="hljs-keyword">var</span> fullName = <span class="hljs-string">&apos;Bob &apos;</span> + <span class="hljs-keyword">this</span>.lastName;
</code></pre>
</li>
<li><p>&#x7A0B;&#x5E8F;&#x5316;&#x751F;&#x6210;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x4F7F;&#x7528; Array#join &#x8FDE;&#x63A5;&#x800C;&#x4E0D;&#x662F;&#x4F7F;&#x7528;&#x8FDE;&#x63A5;&#x7B26;&#x3002;&#x5C24;&#x5176;&#x662F; IE &#x4E0B;&#xFF1A;<a href="http://jsperf.com/string-vs-array-concat/2" target="_blank">jsPerf</a>.</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> items;
<span class="hljs-keyword">var</span> messages;
<span class="hljs-keyword">var</span> length;
<span class="hljs-keyword">var</span> i;

messages = [{
    state: <span class="hljs-string">&apos;success&apos;</span>,
    message: <span class="hljs-string">&apos;This one worked.&apos;</span>
}, {
    state: <span class="hljs-string">&apos;success&apos;</span>,
    message: <span class="hljs-string">&apos;This one worked as well.&apos;</span>
}, {
    state: <span class="hljs-string">&apos;error&apos;</span>,
    message: <span class="hljs-string">&apos;This one did not work.&apos;</span>
}];

length = messages.length;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">inbox</span>(<span class="hljs-params">messages</span>) </span>{
    items = <span class="hljs-string">&apos;&lt;ul&gt;&apos;</span>;

    <span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i &lt; length; i++) {
        items += <span class="hljs-string">&apos;&lt;li&gt;&apos;</span> + messages[i].message + <span class="hljs-string">&apos;&lt;/li&gt;&apos;</span>;
    }

    <span class="hljs-keyword">return</span> items + <span class="hljs-string">&apos;&lt;/ul&gt;&apos;</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> items;
<span class="hljs-keyword">var</span> messages;
<span class="hljs-keyword">var</span> length;
<span class="hljs-keyword">var</span> i;

messages = [{
    state: <span class="hljs-string">&apos;success&apos;</span>,
    message: <span class="hljs-string">&apos;This one worked.&apos;</span>
}, {
    state: <span class="hljs-string">&apos;success&apos;</span>,
    message: <span class="hljs-string">&apos;This one worked as well.&apos;</span>
}, {
    state: <span class="hljs-string">&apos;error&apos;</span>,
    message: <span class="hljs-string">&apos;This one did not work.&apos;</span>
}];

length = messages.length;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">inbox</span>(<span class="hljs-params">messages</span>) </span>{
    items = [];

    <span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i &lt; length; i++) {
        <span class="hljs-comment">// use direct assignment in this case because we&apos;re micro-optimizing.</span>
        items.push(<span class="hljs-string">&apos;&lt;li&gt;&apos;</span> + messages[i].message + <span class="hljs-string">&apos;&lt;/li&gt;&apos;</span>);
    }

    <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;&lt;ul&gt;&apos;</span> + items.join(<span class="hljs-string">&apos;&apos;</span>) + <span class="hljs-string">&apos;&lt;/ul&gt;&apos;</span>;
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x5B57;&#x7B26;&#x4E32;&#x5206;&#x4E24;&#x884C;&#x4E66;&#x5199;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L161" target="_blank"><code>no-multi-str</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testStr = <span class="hljs-string">&apos;Line 1 \
         Line 2&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testStr = <span class="hljs-string">&apos;Line 1\n&apos;</span> +
        <span class="hljs-string">&apos;Line 2&apos;</span>;
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x6CA1;&#x6709;&#x5FC5;&#x8981;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x62FC;&#x63A5;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L272" target="_blank"><code>no-useless-concat</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-string">&apos;some&apos;</span> + <span class="hljs-string">&apos;string&apos;</span>;

<span class="hljs-keyword">var</span> testB = <span class="hljs-string">&apos;1&apos;</span> + <span class="hljs-string">&apos;0&apos;</span>;
</code></pre>
<p><em>[&#x8BF4;&#x660E;] these are the same as &quot;10&quot;. </em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testC = a + b;
<span class="hljs-keyword">var</span> testB = <span class="hljs-string">&apos;1&apos;</span> + a;
<span class="hljs-keyword">var</span> testA = <span class="hljs-number">1</span> + <span class="hljs-string">&apos;1&apos;</span>;
</code></pre>
<p><em>[&#x8BF4;&#x660E;] when a non string is included. </em></p>
</li>
</ul>
<h1 id="&#x51FD;&#x6570;"><a name="&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>9. &#x51FD;&#x6570;</h1>
<ul>
<li><p>&#x6C38;&#x8FDC;&#x4E0D;&#x8981;&#x5728;&#x4E00;&#x4E2A;&#x975E;&#x51FD;&#x6570;&#x4EE3;&#x7801;&#x5757;&#xFF08;if&#x3001;while &#x7B49;&#xFF09;&#x4E2D;&#x58F0;&#x660E;&#x6216;&#x8D4B;&#x503C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x6D4F;&#x89C8;&#x5668;&#x5141;&#x8BB8;&#x4F60;&#x8FD9;&#x4E48;&#x505A;&#xFF0C;&#x4F46;&#x5B83;&#x4EEC;&#x7684;&#x89E3;&#x6790;&#x8868;&#x73B0;&#x4E0D;&#x4E00;&#x81F4;&#xFF0C;&#x6B63;&#x786E;&#x7684;&#x505A;&#x6CD5;&#x662F;&#xFF1A;&#x5728;&#x5757;&#x5916;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x7136;&#x540E;&#x5C06;&#x51FD;&#x6570;&#x8D4B;&#x503C;&#x7ED9;&#x5B83;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L61" target="_blank"><code>no-inner-declarations</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (test) {
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomething</span>(<span class="hljs-params"></span>) </span>{ }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomethingElse</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (test) {
        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doAnotherThing</span>(<span class="hljs-params"></span>) </span>{ }
    }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Yup.&apos;</span>);
};
</code></pre>
</li>
<li><p>&#x6C38;&#x8FDC;&#x4E0D;&#x8981;&#x628A;&#x53C2;&#x6570;&#x547D;&#x540D;&#x4E3A; <code>arguments</code>&#x3002;&#x8FD9;&#x5C06;&#x53D6;&#x4EE3;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x7684; <code>arguments</code> &#x5BF9;&#x8C61;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/variables.js#L28" target="_blank"><code>no-shadow-restricted-names</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">nope</span>(<span class="hljs-params">name, options, arguments</span>) </span>{
    <span class="hljs-comment">// ...stuff...</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">yup</span>(<span class="hljs-params">name, options, args</span>) </span>{
    <span class="hljs-comment">// ...stuff...</span>
}
</code></pre>
</li>
<li><p>&#x5728;&#x51FD;&#x6570;&#x4E2D;&#x6709;&#x5206;&#x652F;&#x65F6;&#xFF0C;&#x4FDD;&#x8BC1;&#x6240;&#x6709;&#x7684;return &#x8BED;&#x53E5;&#x8981;&#x4E48;&#x90FD;&#x6307;&#x5B9A;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x8981;&#x4E48;&#x90FD;&#x4E0D;&#x6307;&#x5B9A;&#x8FD4;&#x56DE;&#x503C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L3" target="_blank"><code>consistent-return</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomething</span>(<span class="hljs-params">condition</span>) </span>{
    <span class="hljs-keyword">if</span> (condition) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span>;
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomething</span>(<span class="hljs-params">condition</span>) </span>{
    <span class="hljs-keyword">if</span> (condition) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomething</span>(<span class="hljs-params">condition</span>) </span>{
    <span class="hljs-keyword">if</span> (condition) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (!(<span class="hljs-keyword">this</span> <span class="hljs-keyword">instanceof</span> Foo)) {
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Foo();
    }

    <span class="hljs-keyword">this</span>.index = <span class="hljs-number">0</span>;
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x51FA;&#x73B0;&#x7A7A;&#x51FD;&#x6570;,&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x5305;&#x542B;&#x4E86;&#x4E00;&#x6761;&#x6CE8;&#x91CA;&#xFF0C;&#x5B83;&#x5C06;&#x4E0D;&#x4F1A;&#x88AB;&#x8BA4;&#x4E3A;&#x6709;&#x95EE;&#x9898;&#xFF0C;&#x8FD9;&#x91CC;&#x5141;&#x8BB8;&#x666E;&#x901A;&#x529F;&#x80FD;&#x51FD;&#x6570;&#x3001;&#x5BF9;&#x8C61;&#x6587;&#x5B57;&#x7684;&#x7C7B;&#x65B9;&#x6CD5;&#x548C;&#x65B9;&#x6CD5;&#x7B80;&#x5199;&#x4E3A;&#x7A7A;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L61" target="_blank"><code>no-empty-function</code></a></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{}
<span class="hljs-keyword">var</span> foo = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{};
<span class="hljs-keyword">var</span> obj = {
    foo: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{}
};
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x7ED9;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x91CD;&#x65B0;&#x8D4B;&#x503C;&#x3002;&#x4E3B;&#x8981;&#x539F;&#x56E0;&#x6709;&#x4E24;&#x70B9;&#xFF0C;&#x4E00;&#x662F;&#x5BF9;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x8FDB;&#x884C;&#x91CD;&#x65B0;&#x8D4B;&#x503C;&#x64CD;&#x4F5C;&#x540E;&#x6700;&#x540E;&#x4F1A;&#x641E;&#x4E0D;&#x6E05;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x7684;&#x521D;&#x59CB;&#x503C;&#xFF0C;&#x4E8C;&#x662F;&#x5982;&#x679C;&#x53C2;&#x6570;&#x662F;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#x7684;&#x53C2;&#x6570;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5BF9;&#x53C2;&#x6570;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#x4F1A;&#x4E5F;&#x4F1A;&#x540C;&#x6837;&#x5F71;&#x54CD;&#x5230;&#x51FD;&#x6570;&#x5916;&#x90E8;&#x6B64;&#x53C2;&#x6570;&#x7684;&#x503C;&#x3002;&#x6B63;&#x786E;&#x7684;&#x505A;&#x6CD5;&#x662F;&#xFF1A;&#x5982;&#x679C;&#x51FD;&#x6570;&#x4E0D;&#x662F;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#x53EF;&#x4EE5;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x5E76;&#x5C06;&#x5176;&#x8D4B;&#x503C;&#x7ED9;&#x8BE5;&#x53D8;&#x91CF;&#xFF1B;&#x5982;&#x679C;&#x53C2;&#x6570;&#x4E3A;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5982;&#x679C;&#x4E3A;&#x5BF9;&#x8C61;&#x7C7B;&#x578B;&#x5219;&#x63A8;&#x8350;&#x4F7F;&#x7528;fish&#x7684;extend&#x65B9;&#x6CD5;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x6570;&#x7EC4;&#x7C7B;&#x578B;&#x7684;&#x63A8;&#x8350;&#x4F7F;&#x7528;Array&#x7684;slice&#x65B9;&#x6CD5;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L182" target="_blank"><code>no-param-reassign</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> test = <span class="hljs-string">&apos;test&apos;</span>;
<span class="hljs-keyword">var</span> testObj = { item:<span class="hljs-string">&apos;item&apos;</span> };
<span class="hljs-keyword">var</span> testArr = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>];

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">test</span>) </span>{
    test = <span class="hljs-string">&apos;abc&apos;</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">testObj</span>) </span>{
    testobj = { bar: <span class="hljs-string">&apos;abc&apos;</span> };
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> test = <span class="hljs-string">&apos;test&apos;</span>;
<span class="hljs-keyword">var</span> testObj = { item:<span class="hljs-string">&apos;item&apos;</span> };
<span class="hljs-keyword">var</span> testArr = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>];

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">test</span>) </span>{
    <span class="hljs-keyword">var</span> bar = test;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">testObj</span>) </span>{
    <span class="hljs-keyword">var</span> test = fish.extend({}, testObj);
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">testArr</span>) </span>{
    <span class="hljs-keyword">var</span> test = testArr.slice();
}
</code></pre>
</li>
<li><p>&#x7ACB;&#x5373;&#x6267;&#x884C;&#x51FD;&#x6570;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x5706;&#x62EC;&#x53F7;&#x5305;&#x56F4;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L324" target="_blank"><code>wrap-iife</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> { y: <span class="hljs-number">1</span> };}();
<span class="hljs-keyword">var</span> testB = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> { y: <span class="hljs-number">1</span> };})();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> { y: <span class="hljs-number">1</span> };}());
</code></pre>
</li>
<li><p>&#x4E0D;&#x5141;&#x8BB8;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x4F7F;&#x7528;&#x76F8;&#x540C;&#x7684;&#x53C2;&#x6570;&#x540D;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L21" target="_blank"><code>no-dupe-args</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">val, index, val</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;value of the second a:&apos;</span>, val);
}
<span class="hljs-keyword">var</span> bar = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">val, index, val</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;value of the second a:&apos;</span>, val);
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">val, index, num</span>) </span>{
    <span class="hljs-built_in">console</span>.log(val, index, num);
}
<span class="hljs-keyword">var</span> bar = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">val, index, num</span>) </span>{
    <span class="hljs-built_in">console</span>.log(val, index, num);
};
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4E66;&#x5199;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x4E0D;&#x5141;&#x8BB8;&#x88AB;&#x91CD;&#x5199;&#x6216;&#x91CD;&#x65B0;&#x8D4B;&#x503C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L58" target="_blank"><code>no-func-assign</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>) </span>{}
foo = bar;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    doSomething();
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{}
<span class="hljs-keyword">var</span> bar = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{}
foo = bar;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">foo</span>) </span>{ <span class="hljs-comment">// `foo` is shadowed.</span>
    foo = bar;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> foo = bar;  <span class="hljs-comment">// `foo` is shadowed.</span>
}
</code></pre>
</li>
<li><p>&#x5728;&#x8C03;&#x7528;&#x4E0D;&#x5E26;&#x53C2;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x65F6;&#x5FC5;&#x987B;&#x52A0;&#x5706;&#x62EC;&#x53F7;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L224" target="_blank"><code>new-parens</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> person = <span class="hljs-keyword">new</span> Person;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> person = <span class="hljs-keyword">new</span> Person();
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4E0D;&#x4E25;&#x683C;&#x8981;&#x6C42;&#x7684;&#x51FD;&#x6570;&#x5C5E;&#x6027;&#x540D;&#x52A0;&#x5F15;&#x53F7;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L422" target="_blank"><code>quote-props</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> object = {
    <span class="hljs-string">&apos;a&apos;</span>: <span class="hljs-number">0</span>,
    <span class="hljs-string">&apos;0&apos;</span>: <span class="hljs-number">0</span>,
    <span class="hljs-string">&apos;true&apos;</span>: <span class="hljs-number">0</span>,
    <span class="hljs-string">&apos;null&apos;</span>: <span class="hljs-number">0</span>
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> object1 = {
    <span class="hljs-string">&apos;a-b&apos;</span>: <span class="hljs-number">0</span>,
    <span class="hljs-string">&apos;0x0&apos;</span>: <span class="hljs-number">0</span>,
    <span class="hljs-string">&apos;1e2&apos;</span>: <span class="hljs-number">0</span>
};
<span class="hljs-keyword">var</span> object2 = {
    foo: <span class="hljs-string">&apos;bar&apos;</span>,
    baz: <span class="hljs-number">42</span>,
    <span class="hljs-literal">true</span>: <span class="hljs-number">0</span>,
    <span class="hljs-number">0</span>: <span class="hljs-number">0</span>,
    <span class="hljs-string">&apos;qux-lorem&apos;</span>: <span class="hljs-literal">true</span>
};
</code></pre>
</li>
</ul>
<h1 id="&#x5C5E;&#x6027;"><a name="&#x5C5E;&#x6027;" class="anchor-navigation-ex-anchor" href="#&#x5C5E;&#x6027;"><i class="fa fa-link" aria-hidden="true"></i></a>10. &#x5C5E;&#x6027;</h1>
<ul>
<li><p>&#x76F4;&#x63A5;&#x901A;&#x8FC7;&#x5C5E;&#x6027;&#x540D;&#x6765;&#x8BBF;&#x95EE;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x65F6;&#xFF0C;&#x4F7F;&#x7528; <code>.</code> &#x6765;&#x8BBF;&#x95EE;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L17" target="_blank"><code>dot-notation</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> luke = {
    jedi: <span class="hljs-literal">true</span>,
    age: <span class="hljs-number">28</span>
};

<span class="hljs-keyword">var</span> isJedi = luke[<span class="hljs-string">&apos;jedi&apos;</span>];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> luke = {
    jedi: <span class="hljs-literal">true</span>,
    age: <span class="hljs-number">28</span>
};

<span class="hljs-keyword">var</span> isJedi = luke.jedi;
</code></pre>
</li>
<li><p>&#x5F53;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x53D8;&#x91CF;&#x95F4;&#x63A5;&#x8BBF;&#x95EE;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x65F6;&#x4F7F;&#x7528;&#x4E2D;&#x62EC;&#x53F7; <code>[]</code>&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> luke = {
    jedi: <span class="hljs-literal">true</span>,
    age: <span class="hljs-number">28</span>
};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getProp</span>(<span class="hljs-params">prop</span>) </span>{
    <span class="hljs-keyword">return</span> luke[prop];
}

<span class="hljs-keyword">var</span> isJedi = getProp(<span class="hljs-string">&apos;jedi&apos;</span>);
</code></pre>
</li>
<li><p>&#x89C4;&#x5B9A;&#x58F0;&#x660E;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x65F6;&#x53EA;&#x80FD;&#x4E00;&#x884C;&#x58F0;&#x660E;&#x6240;&#x6709;&#x7684;&#x5C5E;&#x6027;&#x6216;&#x8005;&#x6BCF;&#x884C;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L393" target="_blank"><code>object-property-newline</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj1 = { foo: <span class="hljs-string">&apos;foo&apos;</span>, bar: <span class="hljs-string">&apos;bar&apos;</span>,
    baz: <span class="hljs-string">&apos;baz&apos;</span>
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj1 = { foo: <span class="hljs-string">&apos;foo&apos;</span>, bar: <span class="hljs-string">&apos;bar&apos;</span>, baz: <span class="hljs-string">&apos;baz&apos;</span> };
<span class="hljs-keyword">var</span> obj2 = {
    foo: <span class="hljs-string">&apos;foo&apos;</span>,
    bar: <span class="hljs-string">&apos;bar&apos;</span>,
    baz: <span class="hljs-string">&apos;baz&apos;</span>
};
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;<strong>proto</strong>&#x5C5E;&#x6027;&#xFF0C;<strong>proto</strong>&#x5C5E;&#x6027;&#x5DF2;&#x4ECE;ECMAScript 3.1&#x5F00;&#x59CB;&#x5F03;&#x7528;&#xFF0C;&#x4E0D;&#x5E94;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x4F7F;&#x7528;&#xFF0C;&#x6539;&#x7528;getPrototypeOf&#x65B9;&#x6CD5;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L194" target="_blank"><code>no-proto</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = obj.__proto__;
<span class="hljs-keyword">var</span> testB = obj[<span class="hljs-string">&apos;__proto__&apos;</span>];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-built_in">Object</span>.getPrototypeOf(obj);
</code></pre>
</li>
<li><p><strong>iterator</strong>&#x5C5E;&#x6027;&#x662F;JavaScript&#x7684;SpiderMonkey&#x6269;&#x5C55;&#xFF0C;&#x53EF;&#x7528;&#x4E8E;&#x521B;&#x5EFA;&#x4E0E;JavaScript for in&#x548C;for each&#x6784;&#x9020;&#x517C;&#x5BB9;&#x7684;&#x81EA;&#x5B9A;&#x4E49;&#x8FED;&#x4EE3;&#x5668;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x6B64;&#x5C5E;&#x6027;&#x73B0;&#x5728;&#x5DF2;&#x8FC7;&#x65F6;&#xFF0C;&#x56E0;&#x6B64;&#x4E0D;&#x5E94;&#x4F7F;&#x7528;&#x5B83;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L128" target="_blank"><code>no-iterator</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">Foo.prototype.__iterator__ = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> FooIterator(<span class="hljs-keyword">this</span>);
};
foo.__iterator__ = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{};
foo[<span class="hljs-string">&apos;__iterator__&apos;</span>] = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{};
</code></pre>
</li>
</ul>
<h1 id="&#x8FD0;&#x7B97;&#x7B26;--&#x7B49;&#x53F7;"><a name="&#x8FD0;&#x7B97;&#x7B26;--&#x7B49;&#x53F7;" class="anchor-navigation-ex-anchor" href="#&#x8FD0;&#x7B97;&#x7B26;--&#x7B49;&#x53F7;"><i class="fa fa-link" aria-hidden="true"></i></a>11. &#x8FD0;&#x7B97;&#x7B26; &amp; &#x7B49;&#x53F7;</h1>
<ul>
<li>&#x4F7F;&#x7528; === &#x548C; !==&#xFF0C;&#x7981;&#x6B62;&#x4F7F;&#x7528; == &#x548C; !=&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L28" target="_blank"><code>eqeqeq</code></a></li>
<li><p>&#x6761;&#x4EF6;&#x8868;&#x8FBE;&#x5F0F;&#x4F8B;&#x5982; <code>if</code> &#x8BED;&#x53E5;&#x901A;&#x8FC7;&#x62BD;&#x8C61;&#x65B9;&#x6CD5; <code>ToBoolean</code> &#x5F3A;&#x5236;&#x8BA1;&#x7B97;&#x5B83;&#x4EEC;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x5E76;&#x4E14;&#x603B;&#x662F;&#x9075;&#x5B88;&#x4E0B;&#x9762;&#x7684;&#x89C4;&#x5219;&#xFF1A;</p>
<ul>
<li><strong>&#x5BF9;&#x8C61;</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>true</strong></li>
<li><strong>Undefined</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong></li>
<li><strong>Null</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong></li>
<li><strong>&#x5E03;&#x5C14;&#x503C;</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>&#x5E03;&#x5C14;&#x7684;&#x503C;</strong></li>
<li><strong>&#x6570;&#x5B57;</strong> &#x5982;&#x679C;&#x662F; <strong>+0&#x3001;-0 &#x6216; NaN</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong>&#xFF0C;&#x5426;&#x5219;&#x4E3A; <strong>true</strong></li>
<li><strong>&#x5B57;&#x7B26;&#x4E32;</strong> &#x5982;&#x679C;&#x662F;&#x7A7A;&#x5B57;&#x7B26;&#x4E32; <code>&apos;&apos;</code> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong>&#xFF0C;&#x5426;&#x5219;&#x4E3A; <strong>true</strong></li>
</ul>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> ([<span class="hljs-number">0</span>]) {
    <span class="hljs-comment">// true</span>
}
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x5BF9;&#x8C61;&#x88AB;&#x8BA1;&#x7B97;&#x4E3A; true&#x3002;</em></p>
</li>
</ul>
<ul>
<li><p>&#x4F7F;&#x7528;&#x5FEB;&#x6377;&#x65B9;&#x5F0F;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (name !== <span class="hljs-string">&apos;&apos;</span>) {
   <span class="hljs-comment">// ...stuff...</span>
}

<span class="hljs-keyword">if</span> (collection.length &gt; <span class="hljs-number">0</span>) {
    <span class="hljs-comment">// ...stuff...</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (name) {
    <span class="hljs-comment">// ...stuff...</span>
}

<span class="hljs-keyword">if</span> (collection.length) {
    <span class="hljs-comment">// ...stuff...</span>
}
</code></pre>
</li>
<li><p>&#x5BF9;&#x4E8E;&#x7EDD;&#x5927;&#x591A;&#x6570;&#x7684;&#x4F7F;&#x7528;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x7ED3;&#x679C;typeof&#x64CD;&#x4F5C;&#x662F;&#x4E0B;&#x5217;&#x5B57;&#x7B26;&#x4E32;&#x5E38;&#x91CF;&#x4E4B;&#x4E00;&#xFF1A;&quot;undefined&quot;&#xFF0C;&quot;object&quot;&#xFF0C;&quot;boolean&quot;&#xFF0C;&quot;number&quot;&#xFF0C;&quot;string&quot;&#xFF0C;&quot;function&quot;&#x548C;&quot;symbol&quot;&#x3002;&#x5C06;typeof&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x7ED3;&#x679C;&#x4E0E;&#x5176;&#x4ED6;&#x5B57;&#x7B26;&#x4E32;&#x6587;&#x5B57;&#x8FDB;&#x884C;&#x6BD4;&#x8F83;&#x901A;&#x5E38;&#x662F;&#x4EE3;&#x7801;&#x7F16;&#x5199;&#x51FA;&#x73B0;&#x9519;&#x8BEF;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L97" target="_blank"><code>valid-typeof</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">typeof</span> foo === <span class="hljs-literal">undefined</span>;
<span class="hljs-keyword">typeof</span> bar === <span class="hljs-built_in">Object</span>;
<span class="hljs-keyword">typeof</span> baz === <span class="hljs-string">&apos;strnig&apos;</span>;
<span class="hljs-keyword">typeof</span> qux === <span class="hljs-string">&apos;some invalid type&apos;</span>;
<span class="hljs-keyword">typeof</span> baz === anotherVariable;
<span class="hljs-keyword">typeof</span> foo === <span class="hljs-number">5</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">typeof</span> foo === <span class="hljs-string">&apos;undefined&apos;</span>;
<span class="hljs-keyword">typeof</span> bar === <span class="hljs-string">&apos;object&apos;</span>;
<span class="hljs-keyword">typeof</span> baz === <span class="hljs-string">&apos;string&apos;</span>;
<span class="hljs-keyword">typeof</span> bar === <span class="hljs-keyword">typeof</span> qux;
</code></pre>
</li>
<li><p>&#x907F;&#x514D;&#x51FA;&#x73B0;&#x4E0E;&#x672C;&#x8EAB;&#x4F5C;&#x6BD4;&#x8F83;&#x7684;&#x8BED;&#x53E5;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L238" target="_blank"><code>no-self-compare</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> item = <span class="hljs-number">10</span>;
<span class="hljs-keyword">if</span> (item === item) {
    item = <span class="hljs-number">20</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">10</span>;
<span class="hljs-keyword">var</span> testB = <span class="hljs-number">10</span>;
<span class="hljs-keyword">if</span> (testA === testB) {
    testA = <span class="hljs-number">20</span>;
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x5BF9;&#x5173;&#x7CFB;&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x5DE6;&#x64CD;&#x4F5C;&#x6570;&#x4F7F;&#x7528;&#x5426;&#x5B9A;&#x8FD0;&#x7B97;&#x7B26;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L90" target="_blank"><code>no-unsafe-negation</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (!key <span class="hljs-keyword">in</span> object) {
    <span class="hljs-comment">// operator precedence makes it equivalent to (!key) in object</span>
    <span class="hljs-comment">// and type conversion makes it equivalent to (key ? &quot;false&quot; : &quot;true&quot;) in object</span>
}
<span class="hljs-keyword">if</span> (!obj <span class="hljs-keyword">instanceof</span> Ctor) {
    <span class="hljs-comment">// operator precedence makes it equivalent to (!obj) instanceof Ctor</span>
    <span class="hljs-comment">// and it equivalent to always false since boolean values are not objects.</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (!(key <span class="hljs-keyword">in</span> object)) {
    <span class="hljs-comment">// key is not in object</span>
}
<span class="hljs-keyword">if</span> (!(obj <span class="hljs-keyword">instanceof</span> Ctor)) {
    <span class="hljs-comment">// obj is not an instance of Ctor</span>
}
<span class="hljs-keyword">if</span>((<span class="hljs-string">&apos;&apos;</span> + !key) <span class="hljs-keyword">in</span> object) {
    <span class="hljs-comment">// make operator precedence and type conversion explicit</span>
    <span class="hljs-comment">// in a rare situation when that is the intended meaning</span>
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x4F4D;&#x8FD0;&#x7B97;&#x7B26;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L250" target="_blank"><code>no-bitwise</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> test = y | z;
<span class="hljs-keyword">var</span> test = y &amp; z;
x |= y;
x &amp;= y;
<span class="hljs-keyword">var</span> test = y ^ z;
<span class="hljs-keyword">var</span> test = ~ z;
<span class="hljs-keyword">var</span> test = y &lt;&lt; z;
<span class="hljs-keyword">var</span> test = y &gt;&gt; z;
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x6DF7;&#x5408;&#x4F7F;&#x7528;&#x4E0D;&#x540C;&#x7684;&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;&#x5982;&#x8FDE;&#x7EED;&#x4F7F;&#x7528;&#x4E0D;&#x5E26;&#x62EC;&#x53F7;&#x7684;&#x4E0D;&#x540C;&#x8FD0;&#x7B97;&#x7B26;&#x3002;&#x7528;&#x62EC;&#x53F7;&#x62EC;&#x8D77;&#x590D;&#x6742;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x53EF;&#x4EE5;&#x6E05;&#x6670;&#x8868;&#x8FBE;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x7684;&#x610F;&#x56FE;&#xFF0C;&#x4F7F;&#x4EE3;&#x7801;&#x66F4;&#x5177;&#x53EF;&#x8BFB;&#x6027;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L269" target="_blank"><code>no-mixed-operators</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = a + b * c;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = a + (b * c);
<span class="hljs-keyword">var</span> foo = (a + b) * c;
</code></pre>
</li>
<li><p>&#x4E09;&#x5143;&#x8FD0;&#x7B97;&#x7B26;&#x7981;&#x6B62;&#x5D4C;&#x5957;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L304" target="_blank"><code>no-nested-ternary</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> thing = foo ? bar : baz === qux ? quxx : foobar;
foo ? baz === qux ? quxx() : foobar() : bar();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> thing = foo ? bar : foobar;
<span class="hljs-keyword">if</span> (foo) {
    thing = bar;
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (baz === qux) {
    thing = quxx;
} <span class="hljs-keyword">else</span> {
    thing = foobar;
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x6CA1;&#x6709;&#x5FC5;&#x8981;&#x7684;&#x4E09;&#x5143;&#x8FD0;&#x7B97;&#x7B26;&#x3002;&#x56E0;&#x4E3A;&#x6709;&#x4E9B;&#x4E09;&#x5143;&#x8FD0;&#x7B97;&#x7B26;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x5176;&#x4ED6;&#x8BED;&#x53E5;&#x66FF;&#x6362;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L356" target="_blank"><code>no-unneeded-ternary</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> test = x === <span class="hljs-number">2</span> ? <span class="hljs-literal">true</span> : <span class="hljs-literal">false</span>;
<span class="hljs-keyword">var</span> test = x === <span class="hljs-number">2</span> ? <span class="hljs-literal">false</span> : <span class="hljs-literal">true</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> test = x === <span class="hljs-number">2</span>;
<span class="hljs-keyword">var</span> test = x !== <span class="hljs-number">2</span>;
</code></pre>
</li>
<li><p>&#x5C3D;&#x53EF;&#x80FD;&#x7684;&#x4F7F;&#x7528;&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x7B80;&#x5199;&#x5F62;&#x5F0F;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L409" target="_blank"><code>operator-assignment</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">1</span>;
<span class="hljs-keyword">var</span> testB = <span class="hljs-number">2</span>;
testA = testA + testB;
testA[<span class="hljs-number">0</span>] = testA[<span class="hljs-number">0</span>] / testB;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">1</span>;
<span class="hljs-keyword">var</span> testB = <span class="hljs-number">2</span>;
testA = testB;
testA += testB;
testA[<span class="hljs-number">0</span>] /= testB;
</code></pre>
</li>
</ul>
<h1 id="&#x5757;"><a name="&#x5757;" class="anchor-navigation-ex-anchor" href="#&#x5757;"><i class="fa fa-link" aria-hidden="true"></i></a>12. &#x5757;</h1>
<ul>
<li><p>if&#x3001;for&#x7B49;&#x8BED;&#x53E5;&#x7684;&#x6267;&#x884C;&#x8BED;&#x53E5;&#x90E8;&#x5206;&#x65E0;&#x8BBA;&#x591A;&#x5C11;&#x53E5;&#x8BED;&#x53E5;&#x90FD;&#x8981;&#x4F7F;&#x7528;&#x62EC;&#x53F7;{}&#x5305;&#x88F9;&#xFF08;&#x53EA;&#x6709;&#x4E00;&#x53E5;&#x8BED;&#x53E5;&#x65F6;&#x4E5F;&#x8981;&#x4F7F;&#x7528;{}&#x5305;&#x88F9;&#xFF09;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L7" target="_blank"><code>curly</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">if</span> (test)
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">if</span> (test) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  }
}
</code></pre>
</li>
<li><p>&#x5982;&#x679C;&#x901A;&#x8FC7; <code>if</code> &#x548C; <code>else</code> &#x4F7F;&#x7528;&#x591A;&#x884C;&#x4EE3;&#x7801;&#x5757;&#xFF0C;&#x628A; <code>else</code> &#x653E;&#x5728; <code>if</code> &#x4EE3;&#x7801;&#x5757;&#x5173;&#x95ED;&#x62EC;&#x53F7;&#x7684;&#x540C;&#x4E00;&#x884C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L13" target="_blank"><code>brace-style</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (test) {
    thing1();
    thing2();
}
<span class="hljs-keyword">else</span> {
    thing3();
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (test) {
    thing1();
    thing2();
} <span class="hljs-keyword">else</span> {
    thing3();
}
</code></pre>
</li>
<li><p>&#x907F;&#x514D;&#x4EE3;&#x7801;&#x4E2D;&#x51FA;&#x73B0;&#x7A7A;&#x7684;&#x4EE3;&#x7801;&#x5757;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L30" target="_blank"><code>no-empty</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (foo) {
}

<span class="hljs-keyword">while</span> (foo) {
}

<span class="hljs-keyword">switch</span>(foo) {
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (foo) {
    <span class="hljs-comment">// empty</span>
}

<span class="hljs-keyword">while</span> (foo) {
    <span class="hljs-comment">/* empty */</span>
}
</code></pre>
</li>
<li><p>&#x4E0D;&#x5141;&#x8BB8;&#x91CD;&#x5199;&#x901A;&#x8FC7;catch&#x4EE3;&#x7801;&#x5757;&#x6355;&#x83B7;&#x5230;&#x7684;&#x9519;&#x8BEF;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L36" target="_blank"><code>no-ex-assign</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">try</span> {
    <span class="hljs-comment">// code</span>
} <span class="hljs-keyword">catch</span> (e) {
    e = <span class="hljs-number">10</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">try</span> {
    <span class="hljs-comment">// code</span>
} <span class="hljs-keyword">catch</span> (e) {
    <span class="hljs-keyword">var</span> foo = <span class="hljs-number">10</span>;
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x5E26;&#x6709;&#x5FAA;&#x73AF;&#x8BED;&#x53E5;&#x6216;switch&#x8BED;&#x53E5;&#x7684;&#x6807;&#x7B7E;&#xFF0C;&#x5E76;&#x4E14;&#x7981;&#x6B62;&#x6807;&#x7B7E;&#x4E0E;break&#x548C;continue&#x4E00;&#x8D77;&#x4F7F;&#x7528;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L132" target="_blank"><code>no-labels</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">label:
    <span class="hljs-keyword">while</span>(<span class="hljs-literal">true</span>) {
        <span class="hljs-keyword">break</span> label;
    }

label:
    <span class="hljs-keyword">while</span>(<span class="hljs-literal">true</span>) {
        <span class="hljs-keyword">continue</span> label;
    }

label:
    <span class="hljs-keyword">switch</span> (a) {
    <span class="hljs-keyword">case</span> <span class="hljs-number">0</span>:
        <span class="hljs-keyword">break</span> label;
    }
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>) {
    <span class="hljs-keyword">break</span>;
}

<span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>) {
    <span class="hljs-keyword">continue</span>;
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x5D4C;&#x5957;&#x5757;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L139" target="_blank"><code>no-lone-blocks</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (foo) {
    bar();
    {
        baz();
    }
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>) </span>{
    {
        baz();
    }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">while</span> (foo) {
    bar();
}
<span class="hljs-keyword">if</span> (foo) {
    <span class="hljs-keyword">if</span> (bar) {
        baz();
    }
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>) </span>{
    baz();
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x5728; finally &#x8BED;&#x53E5;&#x5757;&#x4E2D;&#x51FA;&#x73B0;&#x63A7;&#x5236;&#x6D41;&#x8BED;&#x53E5;&#xFF0C;&#x5982;return&#xFF0C;throw&#x3001;break&#x3001;continue&#x5757;&#x3002;&#x5B83;&#x5141;&#x8BB8;&#x95F4;&#x63A5;&#x4F7F;&#x7528;&#xFF0C;&#x4F8B;&#x5982;&#x5728; function&#x4E2D;&#x5B9A;&#x4E49;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L86" target="_blank"><code>no-unsafe-finally</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">try</span> {
        <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
    } <span class="hljs-keyword">catch</span>(err) {
        <span class="hljs-keyword">return</span> <span class="hljs-number">2</span>;
    } <span class="hljs-keyword">finally</span> {
        <span class="hljs-keyword">return</span> <span class="hljs-number">3</span>;
    }
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">try</span> {
        <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
    } <span class="hljs-keyword">catch</span>(err) {
        <span class="hljs-keyword">return</span> <span class="hljs-number">2</span>;
    } <span class="hljs-keyword">finally</span> {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;hola!&quot;</span>);
    }
};
</code></pre>
</li>
<li><p>&#x6B64;&#x89C4;&#x5219;&#x4E0D;&#x5141;&#x8BB8;&#x5C06;if&#x8BED;&#x53E5;&#x4F5C;&#x4E3A;else&#x5757;&#x4E2D;&#x7684;&#x552F;&#x4E00;&#x8BED;&#x53E5;&#x3002;&#x5982;&#x679C;if&#x8BED;&#x53E5;&#x662F;else&#x5757;&#x4E2D;&#x7684;&#x552F;&#x4E00;&#x8BED;&#x53E5;&#xFF0C;&#x5219;&#x4F7F;&#x7528;else if&#x8868;&#x5355;&#x901A;&#x5E38;&#x66F4;&#x6E05;&#x6670;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L264" target="_blank"><code>no-lonely-if</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (condition) {
    <span class="hljs-comment">// ...</span>
} <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">if</span> (anotherCondition) {
        <span class="hljs-comment">// ...</span>
    }
}

<span class="hljs-keyword">if</span> (condition) {
    <span class="hljs-comment">// ...</span>
} <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">if</span> (anotherCondition) {
        <span class="hljs-comment">// ...</span>
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-comment">// ...</span>
    }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (condition) {
    <span class="hljs-comment">// ...</span>
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (anotherCondition) {
    <span class="hljs-comment">// ...</span>
}

<span class="hljs-keyword">if</span> (condition) {
    <span class="hljs-comment">// ...</span>
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (anotherCondition) {
    <span class="hljs-comment">// ...</span>
} <span class="hljs-keyword">else</span> {
    <span class="hljs-comment">// ...</span>
}
</code></pre>
</li>
<li><p>&#x8981;&#x6C42;&#x6240;&#x6709;&#x7684;switch&#x8BED;&#x53E5;&#x90FD;&#x5FC5;&#x987B;&#x8981;&#x6709;&#x4E00;&#x4E2A;default&#x5206;&#x652F;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x5219;&#x9700;&#x8981;&#x6709;&#x6CE8;&#x91CA;&#x8BF4;&#x660E;&#x662F;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x4E0D;&#x6253;&#x7B97;&#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;&#xFF0C;&#x5426;&#x5219;&#x5C06;&#x4F1A;&#x68C0;&#x6D4B;&#x62A5;&#x9519;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L11" target="_blank"><code>default-case</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> test = <span class="hljs-number">1</span>;
<span class="hljs-keyword">switch</span> (test) {
    <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
        <span class="hljs-comment">/* code */</span>
        <span class="hljs-keyword">break</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">1</span>;
<span class="hljs-keyword">var</span> testB = <span class="hljs-number">1</span>;
<span class="hljs-keyword">switch</span> (testA) {
    <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
        <span class="hljs-comment">/* code */</span>
        <span class="hljs-keyword">break</span>;

    <span class="hljs-keyword">default</span>:
        <span class="hljs-comment">/* code */</span>
        <span class="hljs-keyword">break</span>;
}

<span class="hljs-keyword">switch</span> (testB) {
    <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
        <span class="hljs-comment">/* code */</span>
        <span class="hljs-keyword">break</span>;

    <span class="hljs-comment">// no default</span>
}
</code></pre>
</li>
<li><p>&#x4FDD;&#x8BC1;&#x5728;for-in &#x5FAA;&#x73AF;&#x4E2D;&#x4F7F;&#x7528;&#x4E86;if &#x8BED;&#x53E5;,&#x6CE8;&#x610F;&#x53EA;&#x80FD;&#x904D;&#x5386;&#x5BF9;&#x8C61;&#x81EA;&#x8EAB;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x4E0D;&#x80FD;&#x904D;&#x5386;&#x539F;&#x578B;&#x94FE;&#x4E0A;&#x7684;&#x5C5E;&#x6027;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L35" target="_blank"><code>guard-for-in</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">for</span> (key <span class="hljs-keyword">in</span> foo) {
    <span class="hljs-built_in">console</span>.log(key);
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">for</span> (key <span class="hljs-keyword">in</span> foo) {
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">Object</span>.prototype.hasOwnProperty.call(foo, key)) {
        <span class="hljs-built_in">console</span>.log(key);
    }
}
</code></pre>
</li>
<li><p>&#x5C3D;&#x91CF;&#x4E0D;&#x8981;&#x5728;case/default&#x8BED;&#x53E5;&#x4E2D;&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x58F0;&#x660E;&#xFF0C;&#x5982;&#x679C;&#x8981;&#x4F7F;&#x7528;&#x8BF7;&#x786E;&#x4FDD;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4EC5;&#x9002;&#x7528;&#x4E8E;&#x5F53;&#x524D;case&#x5B50;&#x53E5;&#xFF0C;&#x5C06;&#x5B50;&#x53E5;&#x4F7F;&#x7528;{}&#x5305;&#x88C5;&#x5728;&#x5757;&#x4E2D;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L47" target="_blank"><code>no-case-declarations</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">switch</span> (foo) {
    <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{}
        <span class="hljs-keyword">break</span>;

    <span class="hljs-comment">// no default</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">switch</span> (foo) {
    <span class="hljs-comment">// The following case clauses are wrapped into blocks using brackets</span>
    <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>: {
        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{}
        <span class="hljs-keyword">break</span>;
    }
    <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:
        <span class="hljs-comment">// Declarations using var without brackets are valid due to function-scope hoisting</span>
        <span class="hljs-keyword">var</span> z = <span class="hljs-number">4</span>;
        <span class="hljs-keyword">break</span>;
    <span class="hljs-keyword">default</span>: {
        <span class="hljs-comment">/* code */</span>
        <span class="hljs-keyword">break</span>;
    }
}
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x7981;&#x6B62; if &#x8BED;&#x53E5;&#x4E2D;&#x6709; return &#x4E4B;&#x540E;&#x6709; else&#xFF0C;&#x5982;&#x679C;if&#x5757;&#x5305;&#x542B;return&#x8BED;&#x53E5;&#xFF0C;&#x5219;&#x8BE5;else&#x5757;&#x53D8;&#x5F97;&#x4E0D;&#x5FC5;&#x8981;&#xFF0C;&#x5B83;&#x7684;&#x5185;&#x5BB9;&#x53EF;&#x4EE5;&#x653E;&#x5728;&#x5757;&#x5916;&#x9762;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L57" target="_blank"><code>no-else-return</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (x) {
        <span class="hljs-keyword">return</span> y;
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> z;
    }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (x) {
        <span class="hljs-keyword">return</span> y;
    }

    <span class="hljs-keyword">return</span> z;
}
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x7981;&#x6B62;&#x4E0D;&#x5FC5;&#x8981;&#x7684; .bind() &#x8C03;&#x7528;&#xFF0C;&#x4E3B;&#x8981;&#x662F;&#x51FA;&#x73B0;&#x5728;&#x4E3A;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x7ED1;&#x5B9A;&#x5230;&#x4E86;&#x7279;&#x5B9A;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x4F46;&#x662F;&#x5728;&#x4F60;&#x7684;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x5E76;&#x6CA1;&#x6709;&#x7528;&#x5230;this&#x503C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L81" target="_blank"><code>no-extra-bind</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> boundGetName = (<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getName</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;ESLint&apos;</span>;
}).bind(<span class="hljs-keyword">this</span>);
<span class="hljs-built_in">console</span>.log(boundGetName());
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> boundGetName = (<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getName</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.name;
}).bind(<span class="hljs-keyword">this</span>);
<span class="hljs-built_in">console</span>.log(boundGetName());

<span class="hljs-keyword">var</span> test = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.name;
}.bind(<span class="hljs-keyword">this</span>);
<span class="hljs-built_in">console</span>.log(test());
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x7981;&#x7528;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x6807;&#x7B7E;&#xFF0C;&#x5982;&#x679C;&#x5FAA;&#x73AF;&#x4E0D;&#x5305;&#x542B;&#x5D4C;&#x5957;&#x5FAA;&#x73AF;&#x6216;&#x5F00;&#x5173;&#xFF0C;&#x5219;&#x4E0D;&#x9700;&#x8981;&#x6807;&#x8BB0;&#x5FAA;&#x73AF;&#x3002;&#x60A8;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5220;&#x9664;&#x6807;&#x7B7E;&#x5E76;&#x4F7F;&#x7528;break&#x6216;continue&#x4E0D;&#x4F7F;&#x7528;&#x6807;&#x7B7E;&#x6765;&#x83B7;&#x5F97;&#x76F8;&#x540C;&#x7684;&#x7ED3;&#x679C;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L85" target="_blank"><code>no-extra-label</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">A: <span class="hljs-keyword">while</span> (testA) {
    <span class="hljs-keyword">break</span> A;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">while</span> (testA) {
    <span class="hljs-keyword">break</span>;
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62; case &#x8BED;&#x53E5;&#x843D;&#x7A7A;&#xFF0C;&#x65E8;&#x5728;&#x6D88;&#x9664;&#x4E00;&#x4E2A;case&#x60C5;&#x51B5;&#x5BF9;&#x53E6;&#x4E00;&#x4E2A;case&#x60C5;&#x51B5;&#x7684;&#x7684;&#x65E0;&#x610F;&#x7834;&#x574F;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L90" target="_blank"><code>no-fallthrough</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-number">1</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomething</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> bar = <span class="hljs-number">1</span>;
}
<span class="hljs-keyword">switch</span> (foo) {
    <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
        doSomething();

    <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:
        doSomething();
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-number">1</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomething</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> bar = <span class="hljs-number">1</span>;
}
<span class="hljs-keyword">switch</span> (foo) {
    <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
        doSomething();
        <span class="hljs-keyword">break</span>;

    <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:
        doSomething();
        <span class="hljs-keyword">break</span>;

    <span class="hljs-keyword">default</span>: {
        <span class="hljs-comment">/* code */</span>
        <span class="hljs-keyword">break</span>;
    }
}
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x8981;&#x6C42;&#x5728;&#x4F7F;&#x7528;&#x6D6E;&#x70B9;&#x5C0F;&#x6570;&#x65F6;&#xFF0C;&#x4E0D;&#x80FD;&#x591F;&#x7701;&#x7565;&#x5C0F;&#x6570;&#x70B9;&#x524D;&#x9762;&#x7684;&#x6570;&#x6216;&#x8005;&#x540E;&#x9762;&#x7684;&#x6570;&#xFF0C;&#x5FC5;&#x987B;&#x5199;&#x5168;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L94" target="_blank"><code>no-floating-decimal</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> num = <span class="hljs-number">.5</span>;
<span class="hljs-keyword">var</span> num = <span class="hljs-number">2.</span>;
<span class="hljs-keyword">var</span> num = <span class="hljs-number">-.7</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> num = <span class="hljs-number">0.5</span>;
<span class="hljs-keyword">var</span> num = <span class="hljs-number">2.0</span>;
<span class="hljs-keyword">var</span> num = <span class="hljs-number">-0.7</span>;
</code></pre>
</li>
</ul>
<ul>
<li><p>return &#x8BED;&#x53E5;&#x4E2D;&#x4E0D;&#x80FD;&#x6709;&#x8D4B;&#x503C;&#x8868;&#x8FBE;&#x5F0F;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L221" target="_blank"><code>no-return-assign</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomething</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> foo = bar + <span class="hljs-number">2</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomething</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> foo === bar + <span class="hljs-number">2</span>;
}
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x7981;&#x6B62;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x4F7F;&#x7528;alert, confirm, and prompt, console, debugger&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L39" target="_blank"><code>no-alert</code></a> eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L11" target="_blank"><code>no-console</code></a> eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L20" target="_blank"><code>no-debugger</code></a></p>
</li>
<li><p>&#x7981;&#x6B62;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x4F7F;&#x7528; arguments.caller &#x6216; arguments.callee&#xFF0C;&#x4F7F;&#x7528;arguments.caller&#x548C;arguments.callee&#x8FDB;&#x884C;&#x591A;&#x6B21;&#x4EE3;&#x7801;&#x4F18;&#x5316;&#x662F;&#x4E0D;&#x53EF;&#x80FD;&#x7684;&#x3002;&#x5B83;&#x4EEC;&#x5728;&#x672A;&#x6765;&#x7684;JavaScript&#x7248;&#x672C;&#x4E2D;&#x5DF2;&#x88AB;&#x5F03;&#x7528;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E0B;&#x7981;&#x6B62;&#x5728;ECMAScript 5&#x4E2D;&#x4F7F;&#x7528;&#x5B83;&#x4EEC;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L43" target="_blank"><code>no-caller</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>].map(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
    <span class="hljs-keyword">return</span> !(n &gt; <span class="hljs-number">1</span>) ? <span class="hljs-number">1</span> : <span class="hljs-built_in">arguments</span>.callee(n - <span class="hljs-number">1</span>) * n;
});
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x8BA1;&#x7B97;&#x6570;&#x7EC4;&#x4E2D;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x7684;&#x9636;&#x4E58;&#x3002;</em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>].map(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">factorial</span>(<span class="hljs-params">n</span>) </span>{
    <span class="hljs-keyword">return</span> !(n &gt; <span class="hljs-number">1</span>) ? <span class="hljs-number">1</span> : factorial(n - <span class="hljs-number">1</span>) * n;
});
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x8BA1;&#x7B97;&#x6570;&#x7EC4;&#x4E2D;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x7684;&#x9636;&#x4E58;&#x3002;</em></p>
</li>
</ul>
<ul>
<li><p>&#x7981;&#x6B62;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x4F7F;&#x7528;eval()&#x6216;&#x8005;&#x7C7B;&#x4F3C;&#x4E8E;eval()&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x4F8B;&#x5982;&#x4F7F;&#x7528;setTimeout()&#xFF0C;setInterval()&#x6216;&#x8005;execScript()&#xFF08;&#x4EC5;&#x9650;Internet Explorer&#xFF09;&#xFF0C;&#x6240;&#x6709;&#x8FD9;&#x4E9B;&#x90FD;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x4E00;&#x4E32;JavaScript&#x4EE3;&#x7801;&#x4F5C;&#x4E3A;&#x5B83;&#x4EEC;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8FD9;&#x88AB;&#x8BA4;&#x4E3A;&#x662F;&#x9690;&#x542B;&#x7684;&#xFF0C;eval()&#x56E0;&#x4E3A;&#x4F20;&#x5165;&#x4E86;&#x4E00;&#x4E32;JavaScript&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x89E3;&#x91CA;&#x3002;&#x6240;&#x4EE5;&#x5BF9;&#x4E8E;&#x8FD9;&#x4E24;&#x4E2A;setTimeout()&#x548C;setInterval()&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x5E76;&#x4E14;&#x88AB;&#x8BA4;&#x4E3A;&#x662F;&#x66F4;&#x5B89;&#x5168;&#xFF0C;&#x66F4;&#x9AD8;&#x6027;&#x80FD;&#x3002;&#x5728;&#x94FE;&#x63A5;&#x5730;&#x5740;&#x4E2D;&#x4F7F;&#x7528; javascript: &#x88AB;&#x6709;&#x4E9B;&#x4EBA;&#x8BA4;&#x4E3A;&#x662F; eval &#x7684;&#x4E00;&#x79CD;&#x5F62;&#x5F0F;&#x3002;&#x5728; javascript: &#x94FE;&#x63A5;&#x4E2D;&#x7684;&#x4EE3;&#x7801;&#x5FC5;&#x987B;&#x7531;&#x6D4F;&#x89C8;&#x5668;&#x89E3;&#x6790;&#x548C;&#x8D4B;&#x503C;&#xFF0C;&#x5176;&#x5904;&#x7406;&#x65B9;&#x5F0F;&#x4E0E; eval &#x4E00;&#x6837;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L77" target="_blank"><code>no-eval</code></a> eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L120" target="_blank"><code>no-implied-eval</code></a>  eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L229" target="_blank"><code>no-script-url</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = { x: <span class="hljs-string">&apos;foo&apos;</span> };
<span class="hljs-keyword">var</span> key = <span class="hljs-string">&apos;x&apos;</span>;
<span class="hljs-keyword">var</span> value = <span class="hljs-built_in">eval</span>(<span class="hljs-string">&apos;obj.&apos;</span> + key);
location.href = <span class="hljs-string">&apos;javascript:void(0)&apos;</span>;
setTimeout(<span class="hljs-string">&quot;alert(&apos;Hi!&apos;);&quot;</span>, <span class="hljs-number">100</span>);
setInterval(<span class="hljs-string">&quot;alert(&apos;Hi!&apos;);&quot;</span>, <span class="hljs-number">100</span>);
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x5728;&#x94FE;&#x63A5;&#x5730;&#x5740;&#x4E2D;&#x4F7F;&#x7528; javascript: &#x88AB;&#x8BA4;&#x4E3A;&#x662F; eval &#x7684;&#x4E00;&#x79CD;&#x5F62;&#x5F0F;&#x3002;&#x56E0;&#x4E3A;&#x5728; javascript: &#x94FE;&#x63A5;&#x4E2D;&#x7684;&#x4EE3;&#x7801;&#x5FC5;&#x987B;&#x7531;&#x6D4F;&#x89C8;&#x5668;&#x89E3;&#x6790;&#x548C;&#x8D4B;&#x503C;&#xFF0C;&#x5176;&#x5904;&#x7406;&#x65B9;&#x5F0F;&#x4E0E; eval &#x4E00;&#x6837;&#x3002;</em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = { x: <span class="hljs-string">&apos;foo&apos;</span> };
<span class="hljs-keyword">var</span> key = <span class="hljs-string">&apos;x&apos;</span>;
<span class="hljs-keyword">var</span> value = obj[key];
setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    alert(<span class="hljs-string">&apos;Hi!&apos;</span>);
}, <span class="hljs-number">100</span>);
setInterval(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    alert(<span class="hljs-string">&apos;Hi!&apos;</span>);
}, <span class="hljs-number">100</span>);
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;with&#x8BED;&#x53E5;,with&#x8BED;&#x53E5;&#x53EF;&#x80FD;&#x5B58;&#x5728;&#x95EE;&#x9898;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x5C06;&#x5BF9;&#x8C61;&#x7684;&#x6210;&#x5458;&#x6DFB;&#x52A0;&#x5230;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x4ECE;&#x800C;&#x65E0;&#x6CD5;&#x5206;&#x8FA8;&#x5757;&#x5185;&#x7684;&#x53D8;&#x91CF;&#x5B9E;&#x9645;&#x5F15;&#x7528;&#x7684;&#x5185;&#x5BB9;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L299" target="_blank"><code>no-with</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">with</span> (point) {
    r = <span class="hljs-built_in">Math</span>.sqrt(x * x + y * y); <span class="hljs-comment">// is r a member of point?</span>
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;void&#x65B9;&#x6CD5;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L287" target="_blank"><code>no-void</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">void</span> foo;
<span class="hljs-keyword">var</span> foo = <span class="hljs-keyword">void</span> bar();
</code></pre>
</li>
<li><p>&#x901A;&#x8FC7;throw&#x8BED;&#x53E5;&#x629B;&#x51FA;&#x7684;&#x5BF9;&#x8C61;&#x5FC5;&#x987B;&#x662F;Error&#x5BF9;&#x8C61;&#x672C;&#x8EAB;&#x6216;&#x8005;&#x901A;&#x8FC7;Error&#x5BF9;&#x8C61;&#x5B9A;&#x4E49;&#x7684;&#x5BF9;&#x8C61;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L246" target="_blank"><code>no-throw-literal</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">throw</span> <span class="hljs-string">&apos;error&apos;</span>;
<span class="hljs-keyword">throw</span> <span class="hljs-number">0</span>;
<span class="hljs-keyword">throw</span> <span class="hljs-literal">undefined</span>;
<span class="hljs-keyword">throw</span> <span class="hljs-literal">null</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> e = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;error&apos;</span>);
<span class="hljs-keyword">throw</span> e;
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>();
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;error&apos;</span>);
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x81EA;&#x6211;&#x8D4B;&#x503C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L233" target="_blank"><code>no-self-assign</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-number">1</span>;
<span class="hljs-keyword">var</span> bar = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
foo = foo;
bar = bar;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-number">1</span>;
<span class="hljs-keyword">var</span> bar = <span class="hljs-number">2</span>;
foo = bar;
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x516B;&#x8FDB;&#x5236;&#x6570;&#x5B57;&#x548C;&#x516B;&#x8FDB;&#x5236;&#x7684;&#x8F6C;&#x4E49;&#x5E8F;&#x5217;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L173" target="_blank"><code>no-octal</code></a>  eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L177" target="_blank"><code>no-octal-escape</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> num = <span class="hljs-number">071</span>;
<span class="hljs-keyword">var</span> result = <span class="hljs-number">5</span> + <span class="hljs-number">07</span>;
<span class="hljs-keyword">var</span> foo = <span class="hljs-string">&apos;Copyright \251&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> num = <span class="hljs-string">&apos;0x39&apos;</span>;
<span class="hljs-keyword">var</span> foo = <span class="hljs-string">&apos;Copyright \u00A9&apos;</span>;
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x4EE3;&#x7801;&#x4E2D;&#x7981;&#x6B62;&#x51FA;&#x73B0;&#x6CA1;&#x6709;&#x88AB;&#x4F7F;&#x7528;&#x5230;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x3001;&#x503C;&#x6216;&#x6807;&#x7B7E;&#xFF0C;&#x5E38;&#x89C1;&#x6BD4;&#x5982;&#x77ED;&#x8DEF;&#x8868;&#x8FBE;&#x5F0F;&#x662F;&#x4E0D;&#x5141;&#x8BB8;&#x4F7F;&#x7528;&#x7684;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L255" target="_blank"><code>no-unused-expressions</code></a>  eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L263" target="_blank"><code>no-unused-labels</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">testA &amp;&amp; testB();
testA() || (testB = testC);

A: <span class="hljs-keyword">var</span> foo = <span class="hljs-number">0</span>;
B: {
    foo();
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-literal">true</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">//do something</span>
}
<span class="hljs-keyword">if</span> (foo){
    test();
} <span class="hljs-keyword">else</span> {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;test&apos;</span>);
}
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x8F6C;&#x4E49;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L277" target="_blank"><code>no-useless-escape</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-string">&quot;\&apos;&quot;</span>;
<span class="hljs-string">&apos;\&quot;&apos;</span>;
<span class="hljs-string">&apos;\#&apos;</span>;
<span class="hljs-string">&apos;\e&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-string">&apos;\&apos;&apos;</span>;
<span class="hljs-string">&apos;\\&apos;</span>;
<span class="hljs-string">&apos;\n&apos;</span>;
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x6CA1;&#x6709;&#x5FC5;&#x8981;&#x7684;return&#xFF08;&#x540E;&#x9762;&#x6CA1;&#x6709;&#x8BED;&#x53E5;&#x4E86;&#xFF09;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L282" target="_blank"><code>no-useless-return</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    doSomething();
    <span class="hljs-keyword">return</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> doSomething();
}
</code></pre>
</li>
<li><p>&#x89C4;&#x5B9A;&#x5355;&#x884C;&#x6700;&#x5927;&#x957F;&#x5EA6;&#x4E3A;150&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L170" target="_blank"><code>max-len</code></a></p>
<h1 id="&#x6CE8;&#x91CA;"><a name="&#x6CE8;&#x91CA;" class="anchor-navigation-ex-anchor" href="#&#x6CE8;&#x91CA;"><i class="fa fa-link" aria-hidden="true"></i></a>13. &#x6CE8;&#x91CA;</h1>
</li>
<li><p>&#x8BA9;&#x6CE8;&#x91CA;&#x6709;&#x610F;&#x4E49;&#x3002;&#x91CD;&#x70B9;&#x5728;&#x89E3;&#x91CA;&#x90A3;&#x4E9B;&#x4E0D;&#x5BB9;&#x6613;&#x7ACB;&#x5373;&#x660E;&#x767D;&#x7684;&#x903B;&#x8F91;&#x4E0A;&#x3002;&#x4E0D;&#x8981;&#x628A;&#x8BFB;&#x8005;&#x7684;&#x65F6;&#x95F4;&#x6D6A;&#x8D39;&#x5728;&#x9605;&#x8BFB;&#x7C7B;&#x4F3C;&#x4E8E;:
i = 0; // &#x8BA9;i &#x7B49;&#x4E8E;0</p>
</li>
<li><p>&#x51FD;&#x6570;&#x5934;&#x6CE8;&#x91CA; &#x4F7F;&#x7528; <code>/** ... */</code> &#x4F5C;&#x4E3A;&#x591A;&#x884C;&#x6CE8;&#x91CA;&#x3002;&#x5305;&#x542B;&#x63CF;&#x8FF0;&#x3001;&#x6307;&#x5B9A;&#x6240;&#x6709;&#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C;&#x7684;&#x7C7B;&#x578B;&#x548C;&#x503C;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// make() returns a new element</span>
<span class="hljs-comment">// based on the passed in tag name</span>
<span class="hljs-comment">//</span>
<span class="hljs-comment">// @param {String} tag</span>
<span class="hljs-comment">// @return {Element} element</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">make</span>(<span class="hljs-params">tag</span>) </span>{

    <span class="hljs-comment">// ...stuff...</span>

    <span class="hljs-keyword">return</span> element;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">/**
 * make() returns a new element
 * based on the passed in tag name
 *
 * @param {String} tag
 * @return {Element} element
 */</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">make</span>(<span class="hljs-params">tag</span>) </span>{

    <span class="hljs-comment">// ...stuff...</span>

    <span class="hljs-keyword">return</span> element;
}
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x4F7F;&#x7528; <code>//</code> &#x4F5C;&#x4E3A;&#x5355;&#x884C;&#x6CE8;&#x91CA;&#x3002;&#x5728;&#x6CE8;&#x91CA;&#x5BF9;&#x8C61;&#x4E0A;&#x9762;&#x53E6;&#x8D77;&#x4E00;&#x884C;&#x4F7F;&#x7528;&#x5355;&#x884C;&#x6CE8;&#x91CA;&#x3002;&#x5E76;&#x4E14;&#x5728;&#x5757;&#x6CE8;&#x91CA;&#x524D;&#x8981;&#x63D2;&#x5165;&#x7A7A;&#x884C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L154" target="_blank"><code>lines-around-comment</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getType</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;fetching type...&apos;</span>); <span class="hljs-comment">// This is console.</span>
    <span class="hljs-comment">/* set the default type to &apos;no type&apos;*/</span>
    <span class="hljs-keyword">var</span> type = <span class="hljs-string">&apos;no type&apos;</span>;

    <span class="hljs-keyword">return</span> type;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getType</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// This is console.</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;fetching type...&apos;</span>);

    <span class="hljs-comment">/* set the default type to &apos;no type&apos;*/</span>
    <span class="hljs-keyword">var</span> type = <span class="hljs-string">&apos;no type&apos;</span>;

    <span class="hljs-keyword">return</span> type;
}
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x7ED9;&#x6CE8;&#x91CA;&#x589E;&#x52A0; <code>FIXME</code> &#x6216; <code>TODO</code> &#x7684;&#x524D;&#x7F00;&#x53EF;&#x4EE5;&#x5E2E;&#x52A9;&#x5176;&#x4ED6;&#x5F00;&#x53D1;&#x8005;&#x5FEB;&#x901F;&#x4E86;&#x89E3;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x9700;&#x8981;&#x590D;&#x67E5;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x6216;&#x662F;&#x7ED9;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x7684;&#x529F;&#x80FD;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x89E3;&#x51B3;&#x65B9;&#x5F0F;&#x3002;&#x8FD9;&#x5C06;&#x6709;&#x522B;&#x4E8E;&#x5E38;&#x89C1;&#x7684;&#x6CE8;&#x91CA;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x4EEC;&#x662F;&#x53EF;&#x64CD;&#x4F5C;&#x7684;&#xFF0C;&#x901A;&#x8FC7;&#x68C0;&#x6D4B;&#x540E;&#x5BF9;&#x4EE3;&#x7801;&#x76F8;&#x5E94;&#x7684;&#x6CE8;&#x91CA;&#x5904;&#x5C06;&#x4F1A;&#x53D1;&#x51FA;&#x8B66;&#x544A;&#x3002;&#x4F7F;&#x7528; <code>FIXME -- need to figure this out</code> &#x6216;&#x8005; <code>TODO -- need to implement</code>&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L292" target="_blank"><code>no-warning-comments</code></a></p>
</li>
<li><p>&#x4F7F;&#x7528; <code>// FIXME:</code> &#x6807;&#x6CE8;&#x95EE;&#x9898;&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Calculator</span>(<span class="hljs-params"></span>) </span>{

    <span class="hljs-comment">// <span class="hljs-doctag">FIXME:</span> shouldn&apos;t use a global here</span>
    total = <span class="hljs-number">0</span>;

    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;
}
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528; <code>// TODO:</code> &#x6807;&#x6CE8;&#x95EE;&#x9898;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x5F0F;&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Calculator</span>(<span class="hljs-params"></span>) </span>{

    <span class="hljs-comment">// <span class="hljs-doctag">TODO:</span> total should be configurable by an options param</span>
    <span class="hljs-keyword">this</span>.total = <span class="hljs-number">0</span>;

    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;
}
</code></pre>
</li>
</ul>
<h1 id="&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><a name="&#x7C7B;&#x578B;&#x8F6C;&#x6362;" class="anchor-navigation-ex-anchor" href="#&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><i class="fa fa-link" aria-hidden="true"></i></a>14. &#x7C7B;&#x578B;&#x8F6C;&#x6362;</h1>
<ul>
<li>&#x5728;&#x8BED;&#x53E5;&#x5F00;&#x59CB;&#x65F6;&#x6267;&#x884C;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x3002;</li>
<li><p>&#x5B57;&#x7B26;&#x4E32;&#xFF1A;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">//  =&gt; this.reviewScore = 9;</span>
<span class="hljs-keyword">var</span> totalScore = <span class="hljs-keyword">this</span>.reviewScore + <span class="hljs-string">&apos;&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">//  =&gt; this.reviewScore = 9;</span>
<span class="hljs-keyword">var</span> totalScore = <span class="hljs-string">&apos;&apos;</span> + <span class="hljs-keyword">this</span>.reviewScore;
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;<code>parseInt</code>&#x628A;&#x5B57;&#x7B26;&#x4E32;&#x89E3;&#x6790;&#x6210;&#x6570;&#x503C;&#x65F6;&#x9700;&#x8981;&#x6307;&#x5B9A;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;&#x8F6C;&#x6362;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x57FA;&#x6570;&#xFF08;&#x5373;&#x591A;&#x5C11;&#x8FDB;&#x5236;&#xFF09;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L311" target="_blank"><code>radix</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> inputValue = <span class="hljs-string">&apos;4&apos;</span>;
<span class="hljs-keyword">var</span> val = <span class="hljs-built_in">parseInt</span>(inputValue);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> inputValue = <span class="hljs-string">&apos;4&apos;</span>;
<span class="hljs-keyword">var</span> val = <span class="hljs-built_in">parseInt</span>(inputValue, <span class="hljs-number">10</span>);
</code></pre>
</li>
<li><p>&#x5E03;&#x5C14;:</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> age = <span class="hljs-number">0</span>;
<span class="hljs-keyword">var</span> hasAge = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Boolean</span>(age);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> age = <span class="hljs-number">0</span>;
<span class="hljs-keyword">var</span> hasAge = <span class="hljs-built_in">Boolean</span>(age);
<span class="hljs-keyword">var</span> hasAge = !!age;
</code></pre>
</li>
</ul>
<h1 id="&#x6784;&#x9020;&#x51FD;&#x6570;"><a name="&#x6784;&#x9020;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x6784;&#x9020;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>15. &#x6784;&#x9020;&#x51FD;&#x6570;</h1>
<ul>
<li><p>&#x7ED9;&#x5BF9;&#x8C61;&#x539F;&#x578B;&#x5206;&#x914D;&#x65B9;&#x6CD5;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x65B0;&#x5BF9;&#x8C61;&#x8986;&#x76D6;&#x539F;&#x578B;&#x3002;&#x8986;&#x76D6;&#x539F;&#x578B;&#x5C06;&#x5BFC;&#x81F4;&#x7EE7;&#x627F;&#x51FA;&#x73B0;&#x95EE;&#x9898;&#xFF1A;&#x91CD;&#x8BBE;&#x539F;&#x578B;&#x5C06;&#x8986;&#x76D6;&#x539F;&#x6709;&#x539F;&#x578B;&#xFF01;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Jedi</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;new jedi&apos;</span>);
}

Jedi.prototype = {
    fight: <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fight</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;fighting&apos;</span>);
    },

    block: <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">block</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;blocking&apos;</span>);
    }
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Jedi</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;new jedi&apos;</span>);
}

Jedi.prototype.fight = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fight</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;fighting&apos;</span>);
};

Jedi.prototype.block = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">block</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;blocking&apos;</span>);
};
</code></pre>
</li>
<li><p>&#x7981;&#x6B62;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x4FEE;&#x6539;&#x5185;&#x7F6E;&#x5BF9;&#x8C61;&#x5982;Object&#x3001;Array&#x3001;Function&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-built_in">Object</span>.prototype = {};
</code></pre>
</li>
</ul>
<h1 id="&#x4E8B;&#x4EF6;"><a name="&#x4E8B;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x4E8B;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>16. &#x4E8B;&#x4EF6;</h1>
<ul>
<li><p>&#x5F53;&#x7ED9;&#x4E8B;&#x4EF6;&#x9644;&#x52A0;&#x6570;&#x636E;&#x65F6;&#xFF08;&#x65E0;&#x8BBA;&#x662F; DOM &#x4E8B;&#x4EF6;&#x8FD8;&#x662F;&#x79C1;&#x6709;&#x4E8B;&#x4EF6;&#xFF09;&#xFF0C;&#x4F20;&#x5165;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x800C;&#x4E0D;&#x662F;&#x539F;&#x59CB;&#x503C;&#x3002;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x8BA9;&#x540E;&#x9762;&#x7684;&#x8D21;&#x732E;&#x8005;&#x589E;&#x52A0;&#x66F4;&#x591A;&#x6570;&#x636E;&#x5230;&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#x800C;&#x65E0;&#x9700;&#x627E;&#x51FA;&#x5E76;&#x66F4;&#x65B0;&#x4E8B;&#x4EF6;&#x7684;&#x6BCF;&#x4E00;&#x4E2A;&#x5904;&#x7406;&#x5668;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x4E0D;&#x597D;&#x7684;&#x5199;&#x6CD5;&#xFF1A;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">$(<span class="hljs-keyword">this</span>).trigger(<span class="hljs-string">&apos;listingUpdated&apos;</span>, listing.id);

...

$(<span class="hljs-keyword">this</span>).on(<span class="hljs-string">&apos;listingUpdated&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">e, listingId</span>) </span>{
    <span class="hljs-comment">// do something with listingId</span>
});
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">$(<span class="hljs-keyword">this</span>).trigger(<span class="hljs-string">&apos;listingUpdated&apos;</span>, { listingId : listing.id });

...

$(<span class="hljs-keyword">this</span>).on(<span class="hljs-string">&apos;listingUpdated&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">e, data</span>) </span>{
    <span class="hljs-comment">// do something with data.listingId</span>
});
</code></pre>
</li>
</ul>
<h1 id="&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;"><a name="&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>17. &#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;</h1>
<p>  Fish&#x5C01;&#x88C5;&#x7684;&#x4E00;&#x5957;&#x81EA;&#x5DF1;&#x7684;&#x4EE3;&#x7801;&#x68C0;&#x6D4B;&#x89C4;&#x5219;&#xFF0C;&#x8FD9;&#x4E9B;&#x89C4;&#x5219;&#x90FD;&#x662F;&#x6309;&#x7167;&#x4EE5;&#x4E0A;&#x7684;&#x7F16;&#x7A0B;&#x89C4;&#x8303;&#x6765;&#x5236;&#x5B9A;&#x7684;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x6211;&#x4EEC;&#x7684;&#x4EE3;&#x7801;&#x6587;&#x4EF6;&#x4E2D;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5728;&#x547D;&#x4EE4;&#x884C;&#x4F7F;&#x7528;fish lint&#x547D;&#x4EE4;&#x5373;&#x53EF;&#x4EE5;&#x8F7B;&#x677E;&#x7684;&#x5BF9;JavaScript&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x68C0;&#x6D4B;&#x3002;</p>
<ul>
<li><p>&#x68C0;&#x6D4B;&#x5DE5;&#x5177;</p>
<p>&#x5728;&#x9879;&#x76EE;&#x76EE;&#x5F55;&#x4E2D;&#x6216;&#x5168;&#x5C40;&#x91CC;&#x5B89;&#x88C5;<code>fish-cli</code>&#xFF0C;&#x63A8;&#x8350;&#x5168;&#x5C40;&#x5B89;&#x88C5;</p>
<pre><code class="lang-shell">      $ npm install @ngweb/fish-cli -g --registry=http://npm.iwhalecloud.com:8081/repository/npm-all/
</code></pre>
<p>&#x5728;&#x547D;&#x4EE4;&#x884C;&#x8F93;&#x5165;<code>fish -v</code>&#xFF0C;&#x51FA;&#x73B0;&#x4EE5;&#x4E0B;&#x8FD4;&#x56DE;&#x4E3A;&#x5B89;&#x88C5;&#x6210;&#x529F;&#x3002;</p>
<p><img src="picture/fishversion.png"></p>
</li>
<li><p>&#x4F7F;&#x7528;&#x65B9;&#x6CD5;</p>
<p>&#x8FDB;&#x5165;&#x5230;&#x5230;&#x9879;&#x76EE;&#x76EE;&#x5F55;&#x4E0B;&#xFF0C;&#x5728;&#x547D;&#x4EE4;&#x884C;&#x7EC8;&#x7AEF;&#x8F93;&#x5165;<code>fish lint</code>&#xFF0C;&#x5C31;&#x4F1A;&#x9ED8;&#x8BA4;&#x81EA;&#x52A8;&#x68C0;&#x6D4B;&#x9879;&#x76EE;&#x76EE;&#x5F55;&#x4E0B;&#x7684;modules&#x76EE;&#x5F55;&#x4E0B;&#x548C;app&#x76EE;&#x5F55;&#x4E0B;&#x7684;js&#xFF0C;&#x5E76;&#x751F;&#x6210;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x3002;</p>
</li>
<li><p>&#x4F7F;&#x7528;<code>-dir</code>&#x53C2;&#x6570;&#x81EA;&#x5B9A;&#x4E49;&#x6307;&#x5B9A;&#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x68C0;&#x6D4B;&#x4F60;&#x6240;&#x6307;&#x5B9A;&#x7684;&#x76EE;&#x5F55;&#x4E0B;&#x6240;&#x6709;js&#x6587;&#x4EF6;&#xFF08;&#x4E0D;&#x9012;&#x5F52;&#x68C0;&#x6D4B;&#xFF0C;&#x53EA;&#x68C0;&#x6D4B;&#x6307;&#x5B9A;&#x7684;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x4E0B;&#x7684;js&#xFF09;&#xFF0C;&#x6240;&#x4EE5;&#x786E;&#x4FDD;&#x4F60;&#x6307;&#x5B9A;&#x7684;&#x76EE;&#x5F55;&#x4E0B;&#x5B58;&#x5728;js&#x6587;&#x4EF6;&#x3002;</p>
<pre><code class="lang-shell">      $ fish lint -dir D:/work/testapp/*.js
</code></pre>
<p>&#x68C0;&#x6D4B;&#x6307;&#x5B9A;&#x76EE;&#x5F55;&#x4E0B;&#x6240;&#x6709;&#x5B50;&#x76EE;&#x5F55;&#x4E2D;&#x7684;js&#x6587;&#x4EF6;&#xFF1A;</p>
<pre><code class="lang-shell">      $ fish lint -dir D:/work/testapp/**/*.js
</code></pre>
<p>&#x6307;&#x5B9A;&#x591A;&#x4E2A;&#x8981;&#x68C0;&#x6D4B;&#x7684;js&#x6587;&#x4EF6;&#x8DEF;&#x5F84;&#xFF0C;&#x591A;&#x4E2A;&#x8DEF;&#x5F84;&#x4E4B;&#x95F4;&#x4F7F;&#x7528;&#x7A7A;&#x683C;&#x8FDB;&#x884C;&#x5206;&#x9694;&#xFF1A;</p>
<pre><code class="lang-shell">      $ fish lint -dir D:/work/testapp/*.js D:/work/proj/**/*.js D:/work/test/*.js
</code></pre>
<p>&#x652F;&#x6301;&#x6307;&#x5B9A;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#x8FDB;&#x884C;&#x68C0;&#x6D4B;&#xFF1A;</p>
<pre><code class="lang-shell">      $ fish lint -dir ./test/**/*.js
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x4F7F;&#x7528;<code>-f</code>&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x751F;&#x6210;&#x4E0D;&#x540C;&#x683C;&#x5F0F;&#x7684;&#x9519;&#x8BEF;&#x62A5;&#x544A;&#xFF0C;&#x76EE;&#x524D;&#x652F;&#x6301;&#x751F;&#x6210; checkstyle&#x3001;codeframe&#x3001;compact&#x3001;html&#x3001;jslint-xml&#x3001;json&#x3001;junit&#x3001;stylish&#x3001;table&#x3001;tap&#x3001;unix&#x3001;visualstudio&#x8FD9;&#x4E9B;&#x683C;&#x5F0F;&#x7684;&#x9519;&#x8BEF;&#x62A5;&#x544A;&#x3002;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-shell">      $ fish lint -f html
</code></pre>
</li>
<li><p>&#x914D;&#x7F6E;&#x5FFD;&#x7565;&#x68C0;&#x6D4B;&#x6587;&#x4EF6;</p>
<p>&#x4F7F;&#x7528;&#x7F16;&#x8F91;&#x5668;&#x5728;&#x8981;&#x68C0;&#x6D4B;&#x7684;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA;.eslintignore&#x6587;&#x4EF6;&#xFF0C;&#x5728;&#x8BE5;&#x6587;&#x4EF6;&#x4E2D;&#x914D;&#x7F6E;&#x9700;&#x8981;&#x5FFD;&#x7565;&#x68C0;&#x6D4B;&#x7684;&#x6587;&#x4EF6;&#x8DEF;&#x5F84;&#xFF0C;&#x4E00;&#x884C;&#x914D;&#x7F6E;&#x4E00;&#x4E2A;&#x8DEF;&#x5F84;&#xFF0C;&#x4F8B;&#x5982;&#x4EE5;&#x4E0B;&#x5C31;&#x662F;&#x5FFD;&#x7565;&#x68C0;&#x6D4B;&#x6240;&#x6709;&#x7684;&#x6587;&#x4EF6;&#xFF1A;</p>
<pre><code>      **/*.js
</code></pre><p>&#x5F53; ESLint &#x8FD0;&#x884C;&#x65F6;&#xFF0C;&#x5728;&#x786E;&#x5B9A;&#x54EA;&#x4E9B;&#x6587;&#x4EF6;&#x8981;&#x68C0;&#x6D4B;&#x4E4B;&#x524D;&#xFF0C;&#x5B83;&#x4F1A;&#x5728;&#x5F53;&#x524D;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x4E2D;&#x67E5;&#x627E;&#x4E00;&#x4E2A; .eslintignore &#x6587;&#x4EF6;&#x3002;&#x5982;&#x679C;&#x53D1;&#x73B0;&#x4E86;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;&#x5F53;&#x904D;&#x5386;&#x76EE;&#x5F55;&#x65F6;&#xFF0C;&#x5C06;&#x4F1A;&#x5E94;&#x7528;&#x8FD9;&#x4E9B;&#x504F;&#x597D;&#x8BBE;&#x7F6E;&#x3002;&#x4E00;&#x6B21;&#x53EA;&#x6709;&#x4E00;&#x4E2A; .eslintignore &#x6587;&#x4EF6;&#x4F1A;&#x88AB;&#x4F7F;&#x7528;&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x4E0D;&#x662F;&#x5F53;&#x524D;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x4E0B;&#x7684; .eslintignore &#x6587;&#x4EF6;&#x5C06;&#x4E0D;&#x4F1A;&#x88AB;&#x7528;&#x5230;&#x3002;&#x8BE5;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#x5199;&#x6CD5;&#x9075;&#x5FAA;&#x4E86;glob&#x8BED;&#x6CD5;&#xFF1A;</p>
<ul>
<li>*:&#x5339;&#x914D;&#x4E00;&#x4E2A;&#x8DEF;&#x5F84;&#x90E8;&#x5206;&#x4E2D;0&#x6216;&#x591A;&#x4E2A;&#x5B57;&#x7B26;, &#x6CE8;&#x610F;&#x4E0D;&#x5339;&#x914D;&#x4EE5;.&#x5F00;&#x59CB;&#x7684;&#x8DEF;&#x5F84;,&#x6BD4;&#x5982;.a</li>
<li>**: &#x5339;&#x914D;0&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x5B50;&#x6587;&#x4EF6;&#x5939;</li>
<li>?:&#x5339;&#x914D;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;</li>
<li>{a,b}: &#x5339;&#x914D;a&#x6216;&#x8005;b, a&#x548C;b&#x4E5F;&#x662F;&#x901A;&#x914D;&#x7B26;,&#x53EF;&#x4EE5;&#x7531;&#x5176;&#x4ED6;&#x901A;&#x914D;&#x7B26;&#x7EC4;&#x6210;</li>
<li>!: &#x6392;&#x9664;&#x6587;&#x4EF6;,&#x5982;!a.js&#x8868;&#x793A;&#x6392;&#x9664;&#x6587;&#x4EF6;a.js</li>
</ul>
<p>&#x683C;&#x5F0F;&#x89C4;&#x8303;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>&#x4EE5; # &#x5F00;&#x5934;&#x7684;&#x884C;&#x88AB;&#x5F53;&#x4F5C;&#x6CE8;&#x91CA;&#xFF0C;&#x4E0D;&#x5F71;&#x54CD;&#x5FFD;&#x7565;&#x6A21;&#x5F0F;&#x3002;</li>
<li>&#x8DEF;&#x5F84;&#x662F;&#x76F8;&#x5BF9;&#x4E8E; .eslintignore &#x7684;&#x4F4D;&#x7F6E;&#x6216;&#x5F53;&#x524D;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x3002;</li>
<li>&#x5FFD;&#x7565;&#x6A21;&#x5F0F;&#x540C; .gitignore &#x89C4;&#x8303;&#x3002;</li>
<li>&#x4EE5; ! &#x5F00;&#x5934;&#x7684;&#x884C;&#x662F;&#x5426;&#x5B9A;&#x6A21;&#x5F0F;&#xFF0C;&#x5B83;&#x5C06;&#x4F1A;&#x91CD;&#x65B0;&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x4E4B;&#x524D;&#x88AB;&#x5FFD;&#x7565;&#x7684;&#x6A21;&#x5F0F;&#x3002;</li>
<li>&#x9664;&#x4E86; .eslintignore &#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x6A21;&#x5F0F;&#xFF0C;ESLint&#x603B;&#x662F;&#x5FFD;&#x7565; /node_modules/<em> &#x548C; /bower_components/</em> &#x4E2D;&#x7684;&#x6587;&#x4EF6;&#x3002;</li>
</ul>
<p>&#x4F8B;&#x5982;&#x4EE5;&#x4E0B;&#x5199;&#x6CD5;&#xFF0C;&#x5C31;&#x662F;&#x9996;&#x5148;&#x5FFD;&#x7565;&#x6240;&#x6709;js,&#x7136;&#x540E;&#x53BB;&#x9664;&#x5FFD;&#x7565;<code>code/portal/src/main/webapp/modules/</code>&#x4E0B;&#x7684;&#x6240;&#x6709;js&#xFF0C;&#x6700;&#x7EC8;&#x53EF;&#x4EE5;&#x8FBE;&#x5230;&#x6307;&#x5B9A;&#x68C0;&#x6D4B;&#x8BE5;&#x76EE;&#x5F55;&#x4E2D;js&#x7684;&#x6548;&#x679C;&#xFF1A;</p>
<pre><code>    **/*js
    !code/portal/src/main/webapp/modules/**/*.js
</code></pre></li>
<li><p>&#x5982;&#x4F55;&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;CI/CD&#x68C0;&#x6D4B;&#x6D41;&#x7A0B;</p>
<ol>
<li><p>&#x8FDB;&#x5165;ZCM&#xFF08;10.45.80.26/portal&#xFF09;&#x5E76;&#x767B;&#x9646;&#xFF0C;&#x70B9;&#x51FB;&#x6709;&#x4E0A;&#x89D2;&#x83DC;&#x5355;&#x2014;&#x2014;&gt;&#x5F00;&#x53D1;&#x4E2D;&#x5FC3;&#x2014;&#x2014;&gt;&#x6301;&#x7EED;&#x6784;&#x5EFA;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#xFF1A;</p>
<p><img src="picture/cicd1.png" alt="1555485149590"></p>
</li>
<li><p>&#x8FDB;&#x5165;&#x6301;&#x7EED;&#x6784;&#x5EFA;&#x9875;&#x9762;&#x540E;&#x70B9;&#x51FB;&#x65B0;&#x5EFA;&#x6784;&#x5EFA;&#xFF0C;&#x8FDB;&#x5165;&#x65B0;&#x5EFA;&#x9875;&#x9762;&#x5982;&#x4E0B;&#x56FE;&#xFF0C;&#x914D;&#x7F6E;&#x81EA;&#x5DF1;&#x7684;&#x4EE3;&#x7801;&#x5F52;&#x5C5E;&#xFF0C;&#x5728;&#x8BED;&#x8A00;&#x6A21;&#x677F;&#x5904;&#x9009;&#x62E9;Java+Js&#xFF0C;&#x6700;&#x540E;&#x9009;&#x62E9;&#x8981;&#x6784;&#x5EFA;&#x7684;&#x7684;&#x955C;&#x50CF;&#xFF0C;&#x70B9;&#x51FB;next</p>
<p><img src="picture/cicd4.png" alt="1555485757376"></p>
</li>
<li><p>&#x5728;&#x4EE5;&#x4E0B;&#x9875;&#x9762;&#x9009;&#x62E9;&#x4EA7;&#x54C1;&#x6A21;&#x5757;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x627E;&#x5230;&#x9700;&#x8981;&#x7684;&#x4EA7;&#x54C1;&#x5219;&#x9700;&#x8981;&#x521B;&#x5EFA;&#x4EA7;&#x54C1;&#xFF0C;&#x5B8C;&#x6210;&#x540E;&#x70B9;&#x51FB;next&#x8FDB;&#x884C;&#x4E0B;&#x4E00;&#x6B65;</p>
<p><img src="picture/cicd5.png" alt="1555485837971"></p>
</li>
<li><p>&#x5728;&#x8BE5;&#x9875;&#x9762;&#x6253;&#x5F00;&#x201C;&#x662F;&#x5426;&#x9700;&#x8981;&#x4EE3;&#x7801;&#x5206;&#x6790;&#x9009;&#x9879;&#x201D;&#xFF0C;&#x4E4B;&#x540E;&#x4E00;&#x76F4;&#x70B9;&#x51FB;next&#x5230;&#x6700;&#x540E;&#x4E00;&#x6B65;&#x70B9;&#x51FB;create</p>
<p><img src="picture/cicd6.png" alt="1555485882893"></p>
</li>
<li><p>&#x5728;&#x5982;&#x4E0B;&#x754C;&#x9762;&#x4E2D;&#x7684;&#x70B9;&#x51FB;&#x201C;&#x4EE3;&#x7801;&#x4E0B;&#x8F7D;&#x201D;&#x9009;&#x9879;&#x914D;&#x7F6E;&#x4EE3;&#x7801;&#x4E0B;&#x8F7D;&#x7684;&#x7C7B;&#x578B;&#x3001;&#x8DEF;&#x5F84;&#x3001;&#x7528;&#x6237;&#x540D;&#x3001;&#x5BC6;&#x7801;&#x548C;&#x8981;&#x4E0B;&#x8F7D;&#x7684;&#x5206;&#x652F;&#xFF0C;&#x914D;&#x7F6E;&#x5B8C;&#x6210;&#x540E;&#x70B9;&#x51FB;&#x201C;save&quot;&#x4FDD;&#x5B58;&#x5373;&#x521B;&#x5EFA;&#x5B8C;&#x6210;</p>
<p><img src="picture/cicd7.png" alt="1555486069261"></p>
</li>
<li><p>&#x5982;&#x679C;&#x60F3;&#x8981;&#x914D;&#x7F6E;&#x4F8B;&#x5916;&#x6587;&#x4EF6;&#xFF0C;&#x5219;&#x9996;&#x5148;&#x9700;&#x8981;&#x5728;&#x9879;&#x76EE;&#x7684;CI_Config&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA;.eslintignore&#x6587;&#x4EF6;&#xFF0C;&#x5176;&#x5199;&#x6CD5;&#x53C2;&#x89C1;&#x201C;&#x914D;&#x7F6E;&#x5FFD;&#x7565;&#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x201D;&#x90E8;&#x5206;&#xFF0C;&#x7136;&#x540E;&#x5728;&#x5982;&#x4E0B;&#x754C;&#x9762;&#x4E2D;&#x7684;&#x70B9;&#x51FB;&#x201C;&#x4EE3;&#x7801;&#x5206;&#x6790;&#x201D;&#x9009;&#x9879;&#xFF0C;&#x5C06;&#x5176;&#x4E2D;&#x4F8B;&#x5916;&#x8DEF;&#x5F84;&#x914D;&#x7F6E;&#x4E3A;CI_Config&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x586B;&#x9ED8;&#x8BA4;CI_Config&#x5728;&#x9879;&#x76EE;&#x7684;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#xFF0C;&#x5B8C;&#x6210;&#x540E;&#x70B9;&#x51FB;&#x201C;save&quot;&#x4FDD;&#x5B58;&#x5373;&#x521B;&#x5EFA;&#x5B8C;&#x6210;&#xFF0C;&#x4E0B;&#x9762;&#x4EE5;ngportal&#x4E3A;&#x4F8B;&#x8FDB;&#x884C;&#x914D;&#x7F6E;&#xFF1A;</p>
<ul>
<li>&#x9996;&#x5148;&#x8FDB;&#x5165;ngportal&#x7684;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x7684;CI_Config&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA;.eslintignore&#x6587;&#x4EF6;&#x3002;</li>
</ul>
<p><img src="picture/ngportal1.png" alt="1558335214578"></p>
<ul>
<li><p>&#x5728;.eslintignore&#x6587;&#x4EF6;&#x4E2D;&#x901A;&#x8FC7;&#x9996;&#x5148;&#x5FFD;&#x7565;&#x68C0;&#x6D4B;&#x6240;&#x6709;&#x6587;&#x4EF6;&#xFF0C;&#x7136;&#x540E;&#x6307;&#x5B9A;&#x8981;&#x68C0;&#x6D4B;&#x7684;&#x6587;&#x4EF6;&#x76EE;&#x5F55;&#x7684;&#x5F62;&#x5F0F;&#x8FBE;&#x5230;&#x6307;&#x5B9A;&#x68C0;&#x6D4B;&#x7279;&#x5B9A;&#x76EE;&#x5F55;&#x7684;&#x4EE3;&#x7801;&#x7684;&#x6548;&#x679C;&#xFF0C;&#x6CE8;&#x610F;<code>*.js</code>&#x7684;&#x5199;&#x6CD5;&#xFF0C;&#x4E00;&#x5B9A;&#x8981;&#x544A;&#x8BC9;&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x4F60;&#x9700;&#x8981;&#x68C0;&#x6D4B;&#x7684;&#x662F;&#x8FD9;&#x4E2A;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x6240;&#x6709;js&#x6587;&#x4EF6;&#xFF0C;&#x5426;&#x5219;&#x4F60;&#x7684;&#x8BBE;&#x7F6E;&#x53EF;&#x80FD;&#x5931;&#x6548;&#x3002;</p>
<p><img src="picture/ngportal2.png" alt="1558335555019"></p>
</li>
<li><p>&#x7531;&#x4E8E;&#x6211;&#x4EEC;&#x6309;&#x7167;CICD&#x7684;&#x9ED8;&#x8BA4;&#x8BBE;&#x7F6E;&#x5C06;CI_Config&#x76EE;&#x5F55;&#x521B;&#x5EFA;&#x5728;&#x4E86;&#x9879;&#x76EE;&#x7684;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#xFF0C;&#x6240;&#x4EE5;&#x5728;&#x4E0B;&#x56FE;&#x4E2D;&#x7684;&#x4F8B;&#x5916;&#x8DEF;&#x5F84;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x9ED8;&#x8BA4;&#x4E0D;&#x586B;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x5C06;CI_Config&#x76EE;&#x5F55;&#x6309;&#x7167;&#x7EA6;&#x5B9A;&#x8BBE;&#x7F6E;&#x5728;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x5219;&#x9700;&#x8981;&#x5728;&#x6B64;&#x91CD;&#x65B0;&#x8BBE;&#x7F6E;&#x8DEF;&#x5F84;</p>
<p><img src="picture/cicd10.png" alt="1558333958002"></p>
</li>
</ul>
</li>
<li><p>&#x627E;&#x5230;&#x521B;&#x5EFA;&#x7684;&#x6D41;&#x7A0B;&#x70B9;&#x51FB;&#x6784;&#x5EFA;&#xFF0C;&#x7B49;&#x5F85;&#x6D41;&#x7A0B;&#x6784;&#x5EFA;&#x5B8C;&#x6BD5;&#xFF0C;&#x5728;&#x4E0B;&#x65B9;&#x627E;&#x5230;&#x5BF9;&#x5E94;&#x7684;&#x68C0;&#x6D4B;&#x7ED3;&#x679C;&#xFF0C;&#x70B9;&#x51FB;&#x5373;&#x53EF;&#x67E5;&#x770B;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#xFF1A;</p>
<p><img src="picture/cicd8.png" alt="1555486138948"></p>
<p><img src="picture/cicd9.png" alt="1555486237183"></p>
</li>
</ol>
</li>
</ul>
<h1 id="ide&#x5DE5;&#x5177;&#x914D;&#x7F6E;"><a name="ide&#x5DE5;&#x5177;&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#ide&#x5DE5;&#x5177;&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>18. IDE&#x5DE5;&#x5177;&#x914D;&#x7F6E;</h1>
<h2 id="vscode-eslint&#x914D;&#x7F6E;"><a name="vscode-eslint&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#vscode-eslint&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>18.1. VSCODE ESLINT&#x914D;&#x7F6E;</h2>
<p>  Visual Studio Code (&#x7B80;&#x79F0; VSCode / VSC) &#x662F;&#x4E00;&#x6B3E;&#x514D;&#x8D39;&#x5F00;&#x6E90;&#x7684;&#x73B0;&#x4EE3;&#x5316;&#x8F7B;&#x91CF;&#x7EA7;&#x4EE3;&#x7801;&#x7F16;&#x8F91;&#x5668;&#xFF0C;&#x8F6F;&#x4EF6;&#x8DE8;&#x5E73;&#x53F0;&#x652F;&#x6301; Win&#x3001;Mac &#x4EE5;&#x53CA; Linux&#xFF0C;&#x8FD0;&#x884C;&#x6D41;&#x7545;&#xFF0C;&#x5E76;&#x4E14;&#x4E3A;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x4E86;&#x4E30;&#x5BCC;&#x7684;&#x6269;&#x5C55;&#x5DE5;&#x5177;&#xFF0C;&#x63A8;&#x8350;&#x4F7F;&#x7528;&#x5B83;&#x4F5C;&#x4E3A;&#x6211;&#x4EEC;&#x524D;&#x7AEF;&#x5F00;&#x53D1;&#x7684;&#x5DE5;&#x5177;&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x5C06;&#x4ECB;&#x7ECD;&#x5982;&#x4F55;&#x5728;VSCode&#x5185;&#x914D;&#x7F6E;&#x5B9E;&#x65F6;&#x68C0;&#x6D4B;&#x548C;&#x4E00;&#x952E;&#x683C;&#x5F0F;&#x5316;&#x7684;&#x529F;&#x80FD;&#x3002;</p>
<ul>
<li><p>&#x5B9E;&#x65F6;&#x68C0;&#x6D4B;&#x529F;&#x80FD;&#x914D;&#x7F6E;&#x6B65;&#x9AA4;&#xFF1A;</p>
<ol>
<li><p>&#x9996;&#x5148;&#x9700;&#x8981;&#x8FDB;&#x5165;&#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;&#xFF08;cmd&#xFF09;&#x5168;&#x5C40;&#x5B89;&#x88C5;<code>fish</code>&#x7684;<code>eslint</code>&#x89C4;&#x5219;&#x5305;&#xFF0C;&#x4F7F;&#x7528;&#x5982;&#x4E0B;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre><code class="lang-shell">   $ npm i -g @ztesoft/eslint-config eslint@5.16.0 --registry http://registry.npm.ztesoft.com
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;VSCode&#x6253;&#x5F00;&#x9879;&#x76EE;&#xFF0C;&#x70B9;&#x51FB;VSCode&#x53F3;&#x4FA7;&#x5DE5;&#x5177;&#x680F;&#x4E2D;&#x7684;&#x6269;&#x5C55;&#x9009;&#x9879;&#xFF0C;&#x641C;&#x7D22;eslint&#xFF0C;&#x70B9;&#x51FB;&#x5B89;&#x88C5;</p>
<p><img src="picture/tool1.png" alt="1555641972041"></p>
</li>
<li><p>&#x5B89;&#x88C5;&#x5B8C;&#x6210;&#x540E;&#x91CD;&#x65B0;&#x6253;&#x5F00;VSCode&#x5373;&#x53EF;&#x5728;&#x7F16;&#x5199;js&#x4EE3;&#x7801;&#x65F6;&#x5B9E;&#x65F6;&#x68C0;&#x6D4B;&#x4E0D;&#x7B26;&#x5408;&#x89C4;&#x8303;&#x7684;&#x5199;&#x6CD5;&#xFF0C;&#x5E76;&#x7ED9;&#x51FA;&#x6807;&#x7EA2;&#x63D0;&#x793A;</p>
<p><img src="picture/tool2.png" alt="1555642047193"></p>
</li>
</ol>
</li>
</ul>
<ul>
<li><p>&#x4E00;&#x952E;&#x683C;&#x5F0F;&#x5316;&#x529F;&#x80FD;&#x914D;&#x7F6E;&#xFF1A;</p>
<ol>
<li><p>&#x4F7F;&#x7528;VSCode&#x6253;&#x5F00;&#x9879;&#x76EE;&#xFF0C;&#x70B9;&#x51FB;VSCode&#x53F3;&#x4FA7;&#x5DE5;&#x5177;&#x680F;&#x4E2D;&#x7684;&#x6269;&#x5C55;&#x9009;&#x9879;&#xFF0C;&#x641C;&#x7D22;prettier&#xFF0C;&#x70B9;&#x51FB;&#x5B89;&#x88C5;</p>
<p><img src="picture/tool3.png" alt="1555642133878"></p>
</li>
<li><p>&#x91CD;&#x65B0;&#x6253;&#x5F00;&#x9879;&#x76EE;&#x627E;&#x5230;&#x9700;&#x8981;&#x683C;&#x5F0F;&#x5316;&#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x53F3;&#x952E;&#x9009;&#x62E9;&#x683C;&#x5F0F;&#x5316;&#x6587;&#x6863;&#xFF08;&#x5FEB;&#x6377;&#x952E;&#xFF1A;Shift+Alt+F)&#xFF0C;&#x5373;&#x53EF;&#x4E00;&#x952E;&#x89E3;&#x51B3;&#x4EE3;&#x7801;&#x4E2D;&#x7684;&#x7A7A;&#x683C;&#x3001;&#x9017;&#x53F7;&#x3001;&#x5F15;&#x53F7;&#x3001;&#x5355;&#x884C;&#x957F;&#x5EA6;&#x7B49;&#x683C;&#x5F0F;&#x95EE;&#x9898;</p>
<p><img src="picture/tool4.png" alt="1555642230490"></p>
</li>
</ol>
</li>
</ul>
<ul>
<li><p>&#x6E29;&#x99A8;&#x63D0;&#x793A;&#xFF1A;&#x4EE5;&#x4E0A;&#x5DE5;&#x5177;&#x7684;&#x4F7F;&#x7528;&#x9700;&#x8981;&#x5728;&#x9879;&#x76EE;&#x7684;&#x6839;&#x76EE;&#x5F55;&#x4E2D;&#x6709;<code>.eslintrc.js</code>&#x548C;<code>.prettierrc</code>&#x6587;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x4F7F;&#x7528;fish-cli&#x521B;&#x5EFA;&#x7684;&#x9879;&#x76EE;&#x4E2D;&#x90FD;&#x4F1A;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x8FD9;&#x4E24;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;&#x5F53;&#x7136;&#x5982;&#x679C;&#x4F60;&#x5DF2;&#x7ECF;&#x6309;&#x7167;&#x4E0A;&#x9762;&#x7684;&#x5DE5;&#x5177;&#x5B89;&#x88C5;&#x4E86;fish-cli&#x5E76;&#x4E14;&#x4F7F;&#x7528;&#x7684;<code>fish lint</code>&#x547D;&#x4EE4;&#x5BF9;&#x9879;&#x76EE;&#x8FDB;&#x884C;&#x4E86;&#x68C0;&#x6D4B;&#xFF0C;&#x8FD9;&#x65F6;&#x4E5F;&#x4F1A;&#x5728;&#x4F60;&#x76F8;&#x5E94;&#x7684;&#x76EE;&#x5F55;&#x4E2D;&#x751F;&#x6210;&#x8FD9;&#x4E24;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;&#x5177;&#x4F53;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF0C;&#x8BF7;&#x786E;&#x4FDD;&#x4F60;&#x7684;&#x6587;&#x4EF6;&#x4E0E;&#x6B64;&#x76F8;&#x540C;&#xFF1A;</p>
<p> <img src="picture/tool5.png" alt="1555642888548"></p>
<p> <img src="picture/tool6.png" alt="1555642932643"></p>
<h2 id="idea-eslint-&#x914D;&#x7F6E;"><a name="idea-eslint-&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#idea-eslint-&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>18.2. IDEA ESLINT &#x914D;&#x7F6E;</h2>
</li>
<li><p>idea&#x7F16;&#x8F91;&#x5668;eslint&#x914D;&#x7F6E;&#xFF1A;</p>
<ul>
<li><p>&#x524D;&#x63D0;&#x6761;&#x4EF6;&#xFF1A;</p>
<ol>
<li>&#x5B89;&#x88C5;node.js(&#x63A8;&#x8350;nodejs 12.21.0&#x7248;&#x672C;)</li>
<li>&#x6267;&#x884C;&#x5982;&#x4E0B;&#x547D;&#x4EE4;&#xFF1A;<pre><code class="lang-shell"> $ npm i -g @ztesoft/eslint-config eslint@5.16.0 --registry http://npm.iwhalecloud.com:8081/repository/npm-all/
</code></pre>
</li>
</ol>
</li>
<li><p>&#x914D;&#x7F6E;&#x6B65;&#x9AA4;&#xFF1A;  </p>
<ol>
<li><p>&#x914D;&#x7F6E;JavaScript&#x8BED;&#x8A00;&#x4F7F;&#x7528;ES5&#x8BED;&#x6CD5;</p>
<p><img src="picture/tool7.png" alt="1636438216695"></p>
</li>
<li><p>&#x914D;&#x7F6E;eslint :
 .eslintrc.js &#x57FA;&#x672C;&#x914D;&#x7F6E;&#xFF1A;</p>
<pre><code class="lang-shell">   module.exports = {
     extends: &apos;@ztesoft&apos;
   }
</code></pre>
<p>&#x6CE8;&#xFF1A;&#x53EF;&#x81EA;&#x884C;&#x6309;&#x7167; eslint&#x89C4;&#x5219;&#x6269;&#x5145;&#xFF1B;</p>
<p><img src="picture/tool8.png" alt="1636438216696"></p>
</li>
</ol>
</li>
<li><p>&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#xFF1A;
&#x9009;&#x62E9;&#x9700;&#x8981;&#x68C0;&#x6D4B;js&#x7684;&#x6587;&#x4EF6;&#x6216;&#x6587;&#x4EF6;&#x5939;&#xFF0C;&#x53F3;&#x952E;&#x83DC;&#x5355;&#x9009;&#x62E9; Analyze -&gt; Inspect Code</p>
<p>  <img src="picture/tool9.png" alt="1636438216697">  </p>
</li>
<li><p>&#x7ED3;&#x679C;&#x793A;&#x4F8B;:</p>
<p>  <img src="picture/tool10.png" alt="1636438216698">  </p>
</li>
</ul>
</li>
</ul>
<h1 id="&#x672C;&#x6587;&#x4EF6;&#x8BC4;&#x5BA1;&#x3001;&#x4FEE;&#x6B63;&#x8BB0;&#x5F55;"><a name="&#x672C;&#x6587;&#x4EF6;&#x8BC4;&#x5BA1;&#x3001;&#x4FEE;&#x6B63;&#x8BB0;&#x5F55;" class="anchor-navigation-ex-anchor" href="#&#x672C;&#x6587;&#x4EF6;&#x8BC4;&#x5BA1;&#x3001;&#x4FEE;&#x6B63;&#x8BB0;&#x5F55;"><i class="fa fa-link" aria-hidden="true"></i></a>19. &#x672C;&#x6587;&#x4EF6;&#x8BC4;&#x5BA1;&#x3001;&#x4FEE;&#x6B63;&#x8BB0;&#x5F55;</h1>
<table>
<thead>
<tr>
<th>&#x6587;&#x4EF6;&#x540D;&#x79F0;</th>
<th>Javascript&#x8BED;&#x8A00;&#x7F16;&#x7801;&#x89C4;&#x8303;(es5)</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>&#x5E8F;&#x53F7;</td>
<td>&#x6D41;&#x7A0B;</td>
<td>&#x62DF;&#x5236;&#x4EBA;/&#x5BA1;&#x6838;&#x4EBA;</td>
<td>&#x62DF;&#x5236;/&#x5BA1;&#x6838;&#x65F6;&#x95F4;</td>
<td>&#x7248;&#x672C;&#x53F7;</td>
</tr>
<tr>
<td>1</td>
<td>&#x89C4;&#x8303;&#x53D1;&#x5E03;</td>
<td>&#x738B;&#x5C0F;&#x864E;</td>
<td>2019/4/19</td>
<td>V1.0</td>
</tr>
<tr>
<td>2</td>
<td>&#x5728;&#x7EBF;&#x5316;&#x53D1;&#x5E03;</td>
<td>&#x738B;&#x5C0F;&#x864E;</td>
<td>2021/7/13</td>
<td>V1.1</td>
</tr>
<tr>
<td>3</td>
<td>&#x589E;&#x52A0;18.2. IDEA ESLINT &#x914D;&#x7F6E;</td>
<td>&#x738B;&#x5C0F;&#x864E;</td>
<td>2021/12/30</td>
<td>V1.2</td>
</tr>
</tbody>
</table>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="JavaScript_ES6_ReleasedVersion.html" class="navigation navigation-next navigation-unique" aria-label="Next page: ES6规范">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"ES5规范","level":"1.1.9.1","depth":3,"next":{"title":"ES6规范","level":"1.1.9.2","depth":3,"path":"Language/JavaScript/JavaScript_ES6_ReleasedVersion.md","ref":"Language/JavaScript/JavaScript_ES6_ReleasedVersion.md","articles":[]},"previous":{"title":"JavaScript开发规范","level":"1.1.9","depth":2,"ref":"","articles":[{"title":"ES5规范","level":"1.1.9.1","depth":3,"path":"Language/JavaScript/JavaScript_ES5_ReleasedVersion.md","ref":"Language/JavaScript/JavaScript_ES5_ReleasedVersion.md","articles":[]},{"title":"ES6规范","level":"1.1.9.2","depth":3,"path":"Language/JavaScript/JavaScript_ES6_ReleasedVersion.md","ref":"Language/JavaScript/JavaScript_ES6_ReleasedVersion.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["edit-link","copy-code-button","-lunr","-search","search-pro","anchor-navigation-ex","splitter","emphasize"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"emphasize":{},"splitter":{},"search-pro":{},"page-toc":{"maxDepth":5,"position":"before-first","showByDefault":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"mode":"float","pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"isRewritePageTitle":true,"showLevel":true,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right","showGoTop":true,"isShowTocTitleIcon":true,"tocLevel4Icon":"fa fa-hand-o-right","tocLevel5Icon":"fa fa-hand-o-right","printLog":false,"multipleH1":true,"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false}},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"http://gitlab.iwhalecloud.com/CoP/sql_new/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Sqlrule","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Sqlrule","gitbook":"3.2.3"},"file":{"path":"Language/JavaScript/JavaScript_ES5_ReleasedVersion.md","mtime":"2022-04-18T07:38:53.531Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-04-18T07:39:41.387Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="js/gitbook.js"></script>
    <script src="js/theme.js"></script>
    
        
        <script src="js/plugin.js"></script>
        
    
        
        <script src="js/toggle.js"></script>
        
    
        
        <script src="js/jquery.mark.min.js"></script>
        
    
        
        <script src="js/search.js"></script>
        
    
        
        <script src="js/splitter.js"></script>
        
    
        
        <script src="js/buttons.js"></script>
        
    
        
        <script src="js/fontsettings.js"></script>
        
    

    </body>
</html>

